home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / actionrp / angband_.5 / angband_ / src / spells.c < prev    next >
C/C++ Source or Header  |  1994-04-22  |  142KB  |  5,186 lines

  1. /*
  2.  * spells.c: code for player and creature spells, breaths, wands, scrolls,
  3.  * etc. 
  4.  *
  5.  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke 
  6.  *
  7.  * This software may be copied and distributed for educational, research, and
  8.  * not for profit purposes provided that this copyright and statement are
  9.  * included in all such copies. 
  10.  */
  11.  
  12. #include "constant.h"
  13. #include "config.h"
  14. #include "types.h"
  15. #include "monster.h"
  16. #include "externs.h"
  17.  
  18. #ifdef USG
  19. #ifndef ATARIST_MWC
  20. #include <string.h>
  21. #endif
  22. #else
  23. #ifndef VMS
  24. #include <strings.h>
  25. #endif
  26. #endif
  27.  
  28. #ifndef NO_LINT_ARGS
  29. #ifdef __STDC__
  30. static char bolt_shape(int);
  31. static void ball_destroy(int, int (**) ());
  32. static void pause_if_screen_full(int *, int);
  33. static void spell_hit_monster(monster_type *, int, int *, int, int *, int *);
  34. static void replace_spot(int, int, int);
  35. #else
  36. static char         bolt_shape();
  37. static void         ball_destroy();
  38. static void         pause_if_screen_full();
  39. static void         spell_hit_monster();
  40. static void         replace_spot();
  41. #endif
  42. #endif
  43.  
  44. extern int          set_plasma_destroy();
  45. extern int          set_meteor_destroy();
  46. extern int          set_mana_destroy();
  47. extern int          set_holy_destroy();
  48.  
  49.  
  50. /* Following are spell procedure/functions            -RAK-     */
  51. /* These routines are commonly used in the scroll, potion, wands, and     */
  52. /* staves routines, and are occasionally called from other areas.      */
  53. /* Now included are creature spells also.               -RAK    */
  54.  
  55. static char 
  56. bolt_shape(dir)               /* added for bolts, minor nicety... -CFT */
  57.     int                 dir;
  58. {
  59.     switch (dir) {
  60.       case 1:
  61.       case 9:
  62.     return '/';
  63.       case 2:
  64.       case 8:
  65.     return '|';
  66.       case 3:
  67.       case 7:
  68.     return '\\';
  69.       case 4:
  70.       case 6:
  71.     return '-';
  72.     }
  73.     return '*';               /* should never happen... -CFT */
  74. }
  75.  
  76. /*
  77.  * return the appropriate item destroy test to the typ.  All that's left of
  78.  * get_flags().  -CFT 
  79.  */
  80. /*
  81.  * add new destroys?  maybe GF_FORCE destroy potions, GF_PLASMA as lightning,
  82.  * GF_SHARDS and GF_ICE maybe break things (potions?), and GF_METEOR breaks
  83.  * potions and burns scrolls?  not yet, but it's an idea... -CFT 
  84.  */
  85. static void 
  86. ball_destroy(typ, destroy)
  87.     int                 typ;
  88.     int                 (**destroy) ();
  89.  
  90. {
  91.     switch (typ) {
  92.       case GF_FIRE:
  93.     *destroy = set_fire_destroy;
  94.     break;
  95.       case GF_ACID:
  96.     *destroy = set_acid_destroy;
  97.     break;
  98.       case GF_FROST:
  99.       case GF_SHARDS:
  100.       case GF_ICE:
  101.       case GF_FORCE:
  102.       case GF_SOUND:
  103.     *destroy = set_frost_destroy;    /* just potions and flasks -DGK */
  104.     break;
  105.       case GF_LIGHTNING:
  106.     *destroy = set_lightning_destroy;
  107.     break;
  108.       case GF_PLASMA:           /* DGK */
  109.     *destroy = set_plasma_destroy;    /* fire+lightning -DGK */
  110.     break;
  111.       case GF_METEOR:           /* DGK */
  112.     *destroy = set_meteor_destroy;    /* fire+shards -DGK */
  113.     break;
  114.       case GF_MANA:           /* DGK */
  115.     *destroy = set_mana_destroy;    /* everything -DGK */
  116.     break;
  117.       case GF_HOLY_ORB:       /* DGK */
  118.     *destroy = set_holy_destroy;    /* cursed stuff -DGK */
  119.     break;
  120.       case GF_MAGIC_MISSILE:
  121.       case GF_POISON_GAS:
  122.       case GF_ARROW:
  123.       case GF_NETHER:
  124.       case GF_WATER:
  125.       case GF_CHAOS:
  126.       case GF_CONFUSION:
  127.       case GF_DISENCHANT:
  128.       case GF_NEXUS:
  129.       case GF_INERTIA:
  130.       case GF_LIGHT:
  131.       case GF_DARK:
  132.       case GF_TIME:
  133.       case GF_GRAVITY:
  134.     *destroy = set_null;
  135.     break;
  136.       default:
  137.     msg_print("Unknown typ in ball_destroy().  This may mean trouble.");
  138.     *destroy = set_null;
  139.     break;
  140.     }
  141. }
  142.  
  143. void 
  144. monster_name(m_name, m_ptr, r_ptr)
  145.     char               *m_name;
  146.     monster_type       *m_ptr;
  147.     creature_type      *r_ptr;
  148. {
  149.     if (!m_ptr->ml)
  150.     (void)strcpy(m_name, "It");
  151.     else {
  152.     if (r_ptr->cdefense & UNIQUE)
  153.         (void)sprintf(m_name, "%s", r_ptr->name);
  154.     else
  155.         (void)sprintf(m_name, "The %s", r_ptr->name);
  156.     }
  157. }
  158.  
  159. void 
  160. lower_monster_name(m_name, m_ptr, r_ptr)
  161.     char               *m_name;
  162.     monster_type       *m_ptr;
  163.     creature_type      *r_ptr;
  164. {
  165.     if (!m_ptr->ml)
  166.     (void)strcpy(m_name, "it");
  167.     else {
  168.     if (r_ptr->cdefense & UNIQUE)
  169.         (void)sprintf(m_name, "%s", r_ptr->name);
  170.     else
  171.         (void)sprintf(m_name, "the %s", r_ptr->name);
  172.     }
  173. }
  174.  
  175. /* teleport you a level (or three:-) */
  176. void 
  177. tele_level()
  178. {
  179.     if (dun_level == Q_PLANE)
  180.     dun_level = 0;
  181.     else if (is_quest(dun_level))
  182.     dun_level -= 1;
  183.     else
  184.     dun_level += (-3) + 2 * randint(2);
  185.     if (dun_level < 0)
  186.     dun_level = 0;
  187.     new_level_flag = TRUE;
  188. }
  189.  
  190. /* Sleep creatures adjacent to player            -RAK-     */
  191. int 
  192. sleep_monsters1(y, x)
  193.     int                 y, x;
  194. {
  195.     register int        i, j;
  196.     register cave_type *c_ptr;
  197.     register monster_type *m_ptr;
  198.     register creature_type *r_ptr;
  199.     int                 sleep;
  200.     vtype               out_val, m_name;
  201.  
  202.     sleep = FALSE;
  203.     for (i = y - 1; i <= y + 1; i++)
  204.     for (j = x - 1; j <= x + 1; j++) {
  205.         c_ptr = &cave[i][j];
  206.         if (c_ptr->cptr > 1) {
  207.         m_ptr = &m_list[c_ptr->cptr];
  208.         r_ptr = &c_list[m_ptr->mptr];
  209.  
  210.         monster_name(m_name, m_ptr, r_ptr);
  211.         if ((r_ptr->level >
  212.              randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  213.             (CHARM_SLEEP & r_ptr->cdefense) || (r_ptr->cdefense & UNIQUE)) {
  214.             if (m_ptr->ml && (r_ptr->cdefense & CHARM_SLEEP))
  215.             c_recall[m_ptr->mptr].r_cdefense |= CHARM_SLEEP;
  216.             (void)sprintf(out_val, "%s is unaffected.", m_name);
  217.             msg_print(out_val);
  218.         } else {
  219.             sleep = TRUE;
  220.             m_ptr->csleep = 500;
  221.             (void)sprintf(out_val, "%s falls asleep.", m_name);
  222.             msg_print(out_val);
  223.         }
  224.         }
  225.     }
  226.     return (sleep);
  227. }
  228.  
  229. int 
  230. lose_all_info()
  231. {
  232.     int                 i;
  233.  
  234.     for (i = 0; i <= INVEN_AUX; i++) {
  235.     if (inventory[i].tval != TV_NOTHING)
  236.         inventory[i].ident &= ~(ID_KNOWN2);
  237.     }
  238.     wizard_light(-1);
  239.     return (0);
  240. }
  241.  
  242. void 
  243. identify_pack()
  244. {
  245.     int                 i;
  246.     inven_type         *i_ptr;
  247.  
  248.     for (i = 0; i <= INVEN_AUX; i++) {
  249.     if (inventory[i].tval != TV_NOTHING)
  250.         identify(&i);
  251.     i_ptr = &inventory[i];
  252.     known2(i_ptr);
  253.     }
  254. }
  255.  
  256. /* Detect any treasure on the current panel        -RAK-     */
  257. int 
  258. detect_treasure()
  259. {
  260.     register int        i, j, detect;
  261.     register cave_type *c_ptr;
  262.  
  263.     detect = FALSE;
  264.     for (i = panel_row_min; i <= panel_row_max; i++)
  265.     for (j = panel_col_min; j <= panel_col_max; j++) {
  266.         c_ptr = &cave[i][j];
  267.         if ((c_ptr->tptr != 0) && (t_list[c_ptr->tptr].tval == TV_GOLD) &&
  268.         !test_light(i, j)) {
  269.         c_ptr->fm = TRUE;
  270.         lite_spot(i, j);
  271.         detect = TRUE;
  272.         }
  273.     }
  274.     return (detect);
  275. }
  276.  
  277. int                 special_check();
  278.  
  279.  
  280. /*
  281.  * This will light up all spaces with "magic" items, including potions,
  282.  * scrolls, rods, wands, staves, amulets, rings, and "enchanted" items. This
  283.  * excludes all foods and spell books. -- JND  
  284.  */
  285. int 
  286. detect_magic()
  287. {
  288.     register int        i, j, detect;
  289.     register cave_type *c_ptr;
  290.     register inven_type *t_ptr;
  291.     int                 Tval;
  292.  
  293.     detect = FALSE;
  294.     for (i = panel_row_min; i <= panel_row_max; i++)
  295.     for (j = panel_col_min; j <= panel_col_max; j++) {
  296.         c_ptr = &cave[i][j];
  297.         if ((c_ptr->tptr != 0) && (t_list[c_ptr->tptr].tval < TV_MAX_OBJECT)
  298.         && !test_light(i, j)) {
  299.         t_ptr = &t_list[c_ptr->tptr];
  300.         Tval = t_ptr->tval;
  301.         if (((Tval > 9) && (Tval < 39)) &&    /* Is it a weapon or
  302.                              * armor or light? */
  303.             (((t_ptr->tohit > 0) || (t_ptr->todam) || (t_ptr->toac)
  304.         /* If so, check for plusses on weapons and armor ... */
  305.               || (t_ptr->flags2 & TR_ARTIFACT))
  306.         /* ... and check whether it is an artifact! ;)  */
  307.              || ((Tval > 39) && (Tval < 77)))){    /* Is it otherwise
  308.                              * magical? */
  309.             c_ptr->fm = TRUE;
  310.             lite_spot(i, j);
  311.             detect = TRUE;
  312.         }
  313.         }
  314.     }
  315.     return (detect);
  316. }
  317.  
  318.  
  319.  
  320. int 
  321. detect_enchantment()
  322. {
  323.     register int        i, j, detect;
  324.     register cave_type *c_ptr;
  325.  
  326.     detect = FALSE;
  327.     for (i = panel_row_min; i <= panel_row_max; i++)
  328.     for (j = panel_col_min; j <= panel_col_max; j++) {
  329.         c_ptr = &cave[i][j];
  330.         if ((c_ptr->tptr != 0) && (t_list[c_ptr->tptr].tval < TV_MAX_OBJECT)
  331.         && !test_light(i, j)) {
  332.         if (special_check(&(t_list[c_ptr->tptr]))) {
  333.             c_ptr->fm = TRUE;
  334.             lite_spot(i, j);
  335.             detect = TRUE;
  336.         }
  337.         }
  338.     }
  339.     return (detect);
  340. }
  341.  
  342. int 
  343. detection()
  344. {
  345.     register int        i, detect;
  346.     register monster_type *m_ptr;
  347.  
  348.     detect_treasure();
  349.     detect_object();
  350.     detect_trap();
  351.     detect_sdoor();
  352.  
  353.     detect = FALSE;
  354.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  355.     m_ptr = &m_list[i];
  356.     if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx)) {
  357.         m_ptr->ml = TRUE;
  358.     /* works correctly even if hallucinating */
  359.         print((char)c_list[m_ptr->mptr].cchar, (int)m_ptr->fy,
  360.           (int)m_ptr->fx);
  361.         detect = TRUE;
  362.     }
  363.     }
  364.     if (detect) {
  365.     msg_print("You sense the presence of monsters!");
  366.     msg_print(NULL);
  367.     /* must unlight every monster just lighted */
  368.     creatures(FALSE);
  369.     }
  370.     return (detect);
  371. }
  372.  
  373. /* Detect all objects on the current panel        -RAK-     */
  374. int 
  375. detect_object()
  376. {
  377.     register int        i, j, detect;
  378.     register cave_type *c_ptr;
  379.  
  380.     detect = FALSE;
  381.     for (i = panel_row_min; i <= panel_row_max; i++)
  382.     for (j = panel_col_min; j <= panel_col_max; j++) {
  383.         c_ptr = &cave[i][j];
  384.         if ((c_ptr->tptr != 0) && (t_list[c_ptr->tptr].tval < TV_MAX_OBJECT)
  385.         && !test_light(i, j)) {
  386.         c_ptr->fm = TRUE;
  387.         lite_spot(i, j);
  388.         detect = TRUE;
  389.         }
  390.     }
  391.     return (detect);
  392. }
  393.  
  394.  
  395. /* Locates and displays traps on current panel        -RAK-     */
  396. int 
  397. detect_trap()
  398. {
  399.     register int        i, j;
  400.     int                 detect;
  401.     register cave_type *c_ptr;
  402.     register inven_type *t_ptr;
  403.  
  404.     detect = FALSE;
  405.     for (i = panel_row_min; i <= panel_row_max; i++)
  406.     for (j = panel_col_min; j <= panel_col_max; j++) {
  407.         c_ptr = &cave[i][j];
  408.         if (c_ptr->tptr != 0)
  409.         if (t_list[c_ptr->tptr].tval == TV_INVIS_TRAP) {
  410.             c_ptr->fm = TRUE;
  411.             change_trap(i, j);
  412.             detect = TRUE;
  413.         } else if (t_list[c_ptr->tptr].tval == TV_CHEST) {
  414.             t_ptr = &t_list[c_ptr->tptr];
  415.             known2(t_ptr);
  416.         }
  417.     }
  418.     return (detect);
  419. }
  420.  
  421. void 
  422. stair_creation()
  423. {
  424.     register cave_type *c_ptr;
  425.     register int        cur_pos;
  426.  
  427.     c_ptr = &cave[char_row][char_col];
  428.  
  429.     if ((c_ptr->tptr == 0) ||
  430.     ((t_list[c_ptr->tptr].tval != TV_STORE_DOOR) &&    /* if not store, or */
  431.      ((t_list[c_ptr->tptr].tval < TV_MIN_WEAR) ||    /* if no artifact here
  432.                              * -CFT */
  433.       (t_list[c_ptr->tptr].tval > TV_MAX_WEAR) ||
  434.       !(t_list[c_ptr->tptr].flags2 & TR_ARTIFACT)))) {
  435.     if (c_ptr->tptr != 0)
  436.         (void)delete_object(char_row, char_col);
  437.     cur_pos = popt();
  438.     c_ptr->tptr = cur_pos;
  439.     if ((randint(2) == 1 || is_quest(dun_level)) && (dun_level > 0))
  440.         invcopy(&t_list[cur_pos], OBJ_UP_STAIR);
  441.     else
  442.         invcopy(&t_list[cur_pos], OBJ_DOWN_STAIR);
  443.     } else
  444.     msg_print("The object resists the spell.");
  445. }
  446.  
  447. /* Surround the player with doors.            -RAK-     */
  448. int 
  449. door_creation()
  450. {
  451.     register int        i, j, door;
  452.     int                 k;
  453.     register cave_type *c_ptr;
  454.  
  455.     door = FALSE;
  456.     for (i = char_row - 1; i <= char_row + 1; i++)
  457.     for (j = char_col - 1; j <= char_col + 1; j++)
  458.         if ((i != char_row) || (j != char_col)) {
  459.         c_ptr = &cave[i][j];
  460.         if (c_ptr->fval <= MAX_CAVE_FLOOR) {
  461.             if ((c_ptr->tptr == 0) ||
  462.             ((t_list[c_ptr->tptr].tval != TV_UP_STAIR) 
  463.                 /* if not stairs or a store */
  464.              &&(t_list[c_ptr->tptr].tval != TV_DOWN_STAIR)
  465.              && (t_list[c_ptr->tptr].tval != TV_STORE_DOOR)) ||
  466.             (t_list[c_ptr->tptr].tval < TV_MIN_WEAR) ||
  467.             (t_list[c_ptr->tptr].tval > TV_MAX_WEAR) ||
  468.             !(t_list[c_ptr->tptr].flags2 & TR_ARTIFACT)) {
  469.                 /* if no artifact here -CFT */
  470.             door = TRUE;
  471.             if (c_ptr->tptr != 0)
  472.                 (void)delete_object(i, j);
  473.             k = popt();
  474.             c_ptr->fval = BLOCKED_FLOOR;
  475.             c_ptr->tptr = k;
  476.             invcopy(&t_list[k], OBJ_CLOSED_DOOR);
  477.             lite_spot(i, j);
  478.             } else
  479.             msg_print("The object resists the spell.");
  480.         }
  481.         }
  482.     return (door);
  483. }
  484.  
  485. /* Locates and displays all secret doors on current panel -RAK-     */
  486. int 
  487. detect_sdoor()
  488. {
  489.     register int        i, j, detect;
  490.     register cave_type *c_ptr;
  491.  
  492.     detect = FALSE;
  493.     for (i = panel_row_min; i <= panel_row_max; i++)
  494.     for (j = panel_col_min; j <= panel_col_max; j++) {
  495.         c_ptr = &cave[i][j];
  496.         if (c_ptr->tptr != 0)
  497.         /* Secret doors  */
  498.         if (t_list[c_ptr->tptr].tval == TV_SECRET_DOOR) {
  499.             c_ptr->fm = TRUE;
  500.             change_trap(i, j);
  501.             detect = TRUE;
  502.         }
  503.     /* Staircases     */
  504.         else if (((t_list[c_ptr->tptr].tval == TV_UP_STAIR) ||
  505.               (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR)) &&
  506.              !c_ptr->fm) {
  507.             c_ptr->fm = TRUE;
  508.             lite_spot(i, j);
  509.             detect = TRUE;
  510.         }
  511.     }
  512.     return (detect);
  513. }
  514.  
  515.  
  516. /* Locates and displays all invisible creatures on current panel -RAK- */
  517. int 
  518. detect_invisible()
  519. {
  520.     register int        i, flag;
  521.     register monster_type *m_ptr;
  522.  
  523.     flag = FALSE;
  524.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  525.     m_ptr = &m_list[i];
  526.     if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx) &&
  527.         (CM_INVISIBLE & c_list[m_ptr->mptr].cmove)) {
  528.         m_ptr->ml = TRUE;
  529.     /* works correctly even if hallucinating */
  530.         print((char)c_list[m_ptr->mptr].cchar, (int)m_ptr->fy,
  531.           (int)m_ptr->fx);
  532.         flag = TRUE;
  533.     }
  534.     }
  535.     if (flag) {
  536.     msg_print("You sense the presence of invisible creatures!");
  537.     msg_print(NULL);
  538.     /* must unlight every monster just lighted */
  539.     creatures(FALSE);
  540.     }
  541.     return (flag);
  542. }
  543.  
  544.  
  545. /* Split out of light_line.       -DGK */
  546. void 
  547. mon_light_dam(y, x, dam)
  548.     int                 y, x, dam;
  549. {
  550.     register cave_type *c_ptr;
  551.     register monster_type *m_ptr;
  552.     register creature_type *r_ptr;
  553.     vtype               out_val, m_name;
  554.     int                 i;
  555.  
  556.     c_ptr = &cave[y][x];
  557.     if (c_ptr->cptr > 1) {
  558.     m_ptr = &m_list[c_ptr->cptr];
  559.     r_ptr = &c_list[m_ptr->mptr];
  560.     monster_name(m_name, m_ptr, r_ptr);
  561.     m_ptr->csleep = 0;
  562.     if (HURT_LIGHT & r_ptr->cdefense) {
  563.         if (m_ptr->ml)
  564.         c_recall[m_ptr->mptr].r_cdefense |= HURT_LIGHT;
  565.         i = mon_take_hit((int)c_ptr->cptr, dam, FALSE);
  566.         if (i >= 0) {
  567.         (void)sprintf(out_val, "%s shrivels away in the light!", m_name);
  568.         msg_print(out_val);
  569.         prt_experience();
  570.         } else {
  571.         (void)sprintf(out_val, "%s cringes from the light!", m_name);
  572.         msg_print(out_val);
  573.         }
  574.     }
  575.     }
  576. }
  577.  
  578.  
  579. int 
  580. light_area(y, x, dam, rad)       /* Expanded -DGK */
  581.     register int        y, x, dam, rad;
  582. {
  583.     register int        i, j;
  584.     int                 min_i, max_i, min_j, max_j;
  585.  
  586.     if (rad < 1) rad = 1;    /* sanity check -CWS */
  587.     if (py.flags.blind < 1)
  588.     msg_print("You are surrounded by a white light.");
  589.  
  590.     if ((cave[y][x].fval == LIGHT_FLOOR) && (panel_contains(y, x)))
  591.     light_room(y, x);
  592.  
  593.     if (cave[y][x].lr && (dun_level > 0) && !(cave[y][x].pl))
  594.         light_room(y, x); /* dbd - fix lighting radius */
  595.  
  596.     /* replace a check for in_bounds2 every loop with 4 quick computations -CWS */
  597.     min_i = MY_MAX(0, (y - rad));
  598.     max_i = MY_MIN(cur_height, (y + rad));
  599.     min_j = MY_MAX(0, (x - rad));
  600.     max_j = MY_MIN(cur_width, (x + rad));
  601.  
  602.     for (i = min_i; i <= max_i; i++)
  603.     for (j = min_j; j <= max_j; j++)
  604.         if (los(y, x, i, j) && (distance(y, x, i, j) <= rad)) {
  605.         if (cave[y][x].lr && (dun_level > 0))
  606.             light_room(y, x);
  607.         cave[i][j].pl = TRUE;
  608.         lite_spot(i, j);
  609.         if (dam)
  610.             mon_light_dam(i, j, dam / (rad == 0 ? 1 : rad));
  611.         }
  612.     return (TRUE);
  613. }
  614.  
  615.  
  616. /* Darken an area, opposite of light area        -RAK-     */
  617. int 
  618. unlight_area(y, x)
  619.     int                 y, x;
  620. {
  621.     register int        i, j, unlight;
  622.     register cave_type *c_ptr;
  623.     int                 min_i, max_i, min_j, max_j;
  624.  
  625.     unlight = FALSE;
  626.     if (cave[y][x].lr && (dun_level > 0)) {
  627.     darken_room(y, x);
  628.     unlight = TRUE;           /* this isn't really good, as it returns
  629.                     * true, even if rm was already dark, but
  630.                     * at least scrolls of darkness will be
  631.                     * IDed when used -CFT */
  632.     } else {
  633.     min_i = MY_MAX(0, (y - 3));
  634.     max_i = MY_MIN(cur_height, (y + 3));
  635.     min_j = MY_MAX(0, (x - 3));
  636.     max_j = MY_MIN(cur_width, (x + 3));
  637.     
  638.     /* replace a check for in_bounds2 every loop with 4 quick computations -CWS */
  639.     
  640.     for (i = min_i; i <= max_i; i++)
  641.         for (j = min_j; j <= max_j; j++) {
  642.         c_ptr = &cave[i][j];
  643.         if ((c_ptr->fval == CORR_FLOOR) && (c_ptr->pl || c_ptr->lr)) {
  644.             /* pl could have been set by star-lite wand, etc */
  645.             c_ptr->pl = FALSE;
  646.             c_ptr->tl = FALSE;
  647.             unlight = TRUE;
  648.         }
  649.         }
  650.     }
  651.     if (unlight && py.flags.blind <= 0)
  652.     msg_print("Darkness surrounds you.");
  653.  
  654.     return (unlight);
  655. }
  656.  
  657.  
  658. /* Map the current area plus some            -RAK-     */
  659. void 
  660. map_area()
  661. {
  662.     register cave_type *c_ptr;
  663.     register int        i7, i8, n, m;
  664.     int                 i, j, k, l;
  665.  
  666.     i = panel_row_min - randint(10);
  667.     j = panel_row_max + randint(10);
  668.     k = panel_col_min - randint(20);
  669.     l = panel_col_max + randint(20);
  670.     for (m = i; m <= j; m++)
  671.     for (n = k; n <= l; n++)
  672.         if (in_bounds(m, n) && (cave[m][n].fval <= MAX_CAVE_FLOOR))
  673.         for (i7 = m - 1; i7 <= m + 1; i7++)
  674.             for (i8 = n - 1; i8 <= n + 1; i8++) {
  675.             c_ptr = &cave[i7][i8];
  676.             if (c_ptr->fval >= MIN_CAVE_WALL)
  677.                 c_ptr->pl = TRUE;
  678.             else if ((c_ptr->tptr != 0) &&
  679.                  (t_list[c_ptr->tptr].tval >= TV_MIN_VISIBLE) &&
  680.                    (t_list[c_ptr->tptr].tval <= TV_MAX_VISIBLE))
  681.                 c_ptr->fm = TRUE;
  682.             }
  683.     prt_map();
  684. }
  685.  
  686.  
  687. /* Identify an object                    -RAK-     */
  688. int 
  689. ident_spell()
  690. {
  691.     int                 item_val;
  692.     bigvtype            out_val, tmp_str;
  693.     register int        ident;
  694.     register inven_type *i_ptr;
  695.  
  696.     ident = FALSE;
  697.     if (get_item(&item_val, "Item you wish identified?", 0, INVEN_ARRAY_SIZE, 0)) {
  698.     ident = TRUE;
  699.     identify(&item_val);
  700.     i_ptr = &inventory[item_val];
  701.     known2(i_ptr);
  702.     objdes(tmp_str, i_ptr, TRUE);
  703.     if (item_val >= INVEN_WIELD) {
  704.         calc_bonuses();
  705.         (void)sprintf(out_val, "%s: %s", describe_use(item_val), tmp_str);
  706.     } else
  707.         (void)sprintf(out_val, "%c %s", item_val + 97, tmp_str);
  708.     msg_print(out_val);
  709.     }
  710.     return (ident);
  711. }
  712.  
  713.  
  714. /* Get all the monsters on the level pissed off.    -RAK-     */
  715. int 
  716. aggravate_monster(dis_affect)
  717.     int                 dis_affect;
  718. {
  719.     register int        i, aggravate;
  720.     register monster_type *m_ptr;
  721.  
  722.     aggravate = FALSE;
  723.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  724.     m_ptr = &m_list[i];
  725.     m_ptr->csleep = 0;
  726.     if ((m_ptr->cdis <= dis_affect) && (m_ptr->cspeed < 2)) {
  727.         m_ptr->cspeed++;
  728.         aggravate = TRUE;
  729.     }
  730.     }
  731.     if (aggravate)
  732.     msg_print("You hear a sudden stirring in the distance!");
  733.     return (aggravate);
  734. }
  735.  
  736.  
  737. /* Surround the fool with traps (chuckle)        -RAK-     */
  738. int 
  739. trap_creation()
  740. {
  741.     register int        i, j, trap;
  742.     register cave_type *c_ptr;
  743.  
  744.     trap = FALSE;
  745.     for (i = char_row - 1; i <= char_row + 1; i++)
  746.     for (j = char_col - 1; j <= char_col + 1; j++) {
  747.         if ((i == char_row) && (j == char_col))
  748.         continue;       /* no trap under player, from um55 -CFT */
  749.         c_ptr = &cave[i][j];
  750.         if (c_ptr->fval <= MAX_CAVE_FLOOR) {
  751.         if ((c_ptr->tptr == 0) ||
  752.             ((t_list[c_ptr->tptr].tval != TV_UP_STAIR)
  753.              /* if not stairs or a store */
  754.              &&(t_list[c_ptr->tptr].tval != TV_DOWN_STAIR)
  755.              && (t_list[c_ptr->tptr].tval != TV_STORE_DOOR)) ||
  756.             (t_list[c_ptr->tptr].tval < TV_MIN_WEAR) ||
  757.             (t_list[c_ptr->tptr].tval > TV_MAX_WEAR) ||
  758.             !(t_list[c_ptr->tptr].flags2 & TR_ARTIFACT)) {
  759.                 /* if no artifact here -CFT */
  760.             trap = TRUE;
  761.             if (c_ptr->tptr != 0)
  762.             (void)delete_object(i, j);
  763.             place_trap(i, j, randint(MAX_TRAP) - 1);
  764.         /* don't let player gain exp from the newly created traps */
  765.             t_list[c_ptr->tptr].p1 = 0;
  766.         /* open pits are immediately visible, so call lite_spot */
  767.             lite_spot(i, j);
  768.         } else
  769.             msg_print("The object resists the spell.");
  770.         }
  771.     }
  772.     return (trap);
  773. }
  774.  
  775.  
  776. /* Destroys any adjacent door(s)/trap(s)        -RAK-     */
  777. int 
  778. td_destroy()
  779. {
  780.     register int        i, j, destroy;
  781.     register cave_type *c_ptr;
  782.  
  783.     destroy = FALSE;
  784.     for (i = char_row - 1; i <= char_row + 1; i++)
  785.     for (j = char_col - 1; j <= char_col + 1; j++) {
  786.         c_ptr = &cave[i][j];
  787.         if (c_ptr->tptr != 0) {
  788.         if (((t_list[c_ptr->tptr].tval >= TV_INVIS_TRAP) &&
  789.              (t_list[c_ptr->tptr].tval <= TV_CLOSED_DOOR) &&
  790.              (t_list[c_ptr->tptr].tval != TV_RUBBLE)) ||
  791.             (t_list[c_ptr->tptr].tval == TV_SECRET_DOOR)) {
  792.             if (delete_object(i, j))
  793.             destroy = TRUE;
  794.         } else if (t_list[c_ptr->tptr].tval == TV_CHEST) {
  795.         /* destroy traps on chest and unlock */
  796.             t_list[c_ptr->tptr].flags &= ~(CH_TRAPPED | CH_LOCKED);
  797.             t_list[c_ptr->tptr].name2 = SN_DISARMED;
  798.             msg_print("You have disarmed the chest.");
  799.             known2(&t_list[c_ptr->tptr]);
  800.             destroy = TRUE;
  801.         }
  802.         }
  803.     }
  804.     return (destroy);
  805. }
  806.  
  807.  
  808. /* Display all creatures on the current panel        -RAK-     */
  809. int 
  810. detect_monsters()
  811. {
  812.     register int        i, detect;
  813.     register monster_type *m_ptr;
  814.  
  815.     detect = FALSE;
  816.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  817.     m_ptr = &m_list[i];
  818.     if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx) &&
  819.         ((CM_INVISIBLE & c_list[m_ptr->mptr].cmove) == 0)) {
  820.         m_ptr->ml = TRUE;
  821.     /* works correctly even if hallucinating */
  822.         print((char)c_list[m_ptr->mptr].cchar, (int)m_ptr->fy,
  823.           (int)m_ptr->fx);
  824.         detect = TRUE;
  825.     }
  826.     }
  827.     if (detect) {
  828.     msg_print("You sense the presence of monsters!");
  829.     msg_print(NULL);
  830.     /* must unlight every monster just lighted */
  831.     creatures(FALSE);
  832.     }
  833.     return (detect);
  834. }
  835.  
  836.  
  837. /* Leave a line of light in given dir, blue light can sometimes     */
  838. /* hurt creatures.                       -RAK-   */
  839. void 
  840. light_line(dir, y, x)
  841.     int                 dir, y, x;
  842. {
  843.     register cave_type *c_ptr;
  844.     int                 dist, flag;
  845.  
  846.     dist = (-1);
  847.     flag = FALSE;
  848.     do {
  849.     /* put mmove at end because want to light up current spot */
  850.     dist++;
  851.     c_ptr = &cave[y][x];
  852.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  853.         flag = TRUE;
  854.     if (!c_ptr->pl && !c_ptr->tl) {
  855.     /* set pl so that lite_spot will work */
  856.         c_ptr->pl = TRUE;
  857.         if (c_ptr->fval == LIGHT_FLOOR) {
  858.         if (panel_contains(y, x))
  859.             light_room(y, x);
  860.         } else
  861.         lite_spot(y, x);
  862.     }
  863.     /* set pl in case tl was true above */
  864.     c_ptr->pl = TRUE;
  865.     mon_light_dam(y, x, damroll(6, 8));
  866.     (void)mmove(dir, &y, &x);
  867.     }
  868.     while (!flag);
  869. }
  870.  
  871.  
  872. /* Leave a line of frost in given dir -DGK */
  873. void 
  874. frost_line(dir, y, x, dam)
  875.     int                 dir, y, x, dam;
  876. {
  877.     register int        i;
  878.     register cave_type *c_ptr;
  879.     register monster_type *m_ptr;
  880.     register creature_type *r_ptr;
  881.     int                 dist, flag, d;
  882.     vtype               out_val, cdesc;
  883.     int                 xx, yy;
  884.  
  885.     xx = x;
  886.     yy = y;
  887.     dist = (-1);
  888.     flag = FALSE;
  889.     do {
  890.     /* put mmove at end because want to damage current spot */
  891.     dist++;
  892.     c_ptr = &cave[y][x];
  893.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  894.         flag = TRUE;
  895.     else {
  896.     /* print a blue * at y,x */
  897.         if (panel_contains(y, x)) {
  898. #ifdef TC_COLOR
  899.         if (!no_color_flag)
  900.             textcolor(bolt_color(GF_FROST));
  901. #endif
  902.         print('*', y, x);
  903. #ifdef TC_COLOR
  904.         if (!no_color_flag)
  905.             textcolor(LIGHTGRAY);    /* prob don't need here,
  906.                          * but... -CFT */
  907. #endif
  908.         }
  909.         if (c_ptr->cptr > 1) {
  910.         m_ptr = &m_list[c_ptr->cptr];
  911.         r_ptr = &c_list[m_ptr->mptr];
  912.         /* light up and draw monster */
  913.         update_mon((int)c_ptr->cptr);
  914.         m_ptr->csleep = 0;
  915.         if (m_ptr->ml) {
  916.             if (r_ptr->cdefense & UNIQUE)
  917.             sprintf(cdesc, "%s", r_ptr->name);
  918.             else
  919.             sprintf(cdesc, "The %s", r_ptr->name);
  920.         } else
  921.             strcpy(cdesc, "It");
  922.         if (r_ptr->cdefense & IM_FROST) {
  923.             if (!(py.flags.status & PY_BLIND)) {
  924.             sprintf(out_val, "%s resists.", cdesc);
  925.             msg_print(out_val);
  926.             }
  927.             d = dam / 9;
  928.             if (m_ptr->ml)
  929.             c_recall[m_ptr->mptr].r_cdefense |= IM_FROST;
  930.         } else
  931.             d = dam;
  932.         i = mon_take_hit((int)c_ptr->cptr, d, TRUE);
  933.         if (i >= 0) {
  934.             (void)sprintf(out_val,
  935.                   "%s dies in a fit of agony.", cdesc);
  936.             msg_print(out_val);
  937.             prt_experience();
  938.         } else {
  939.             (void)sprintf(out_val,
  940.                   pain_message((int)c_ptr->cptr, d), cdesc);
  941.             msg_print(out_val);
  942.         }
  943.         }
  944.     }
  945.     (void)mmove(dir, &y, &x);
  946.     }
  947.     while (!flag);
  948.  
  949. #ifdef MSDOS
  950.     delay(30 * delay_spd);       /* millisecs */
  951. #else
  952.     usleep(30000 * delay_spd);       /* useconds */
  953. #endif
  954.  
  955. /* Now go through and erase the line. */
  956.     dist = (-1);
  957.     flag = FALSE;
  958.     do {
  959.     /* put mmove at end because want to damage current spot */
  960.     dist++;
  961.     c_ptr = &cave[yy][xx];
  962.     if ((dist >= OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  963.         flag = TRUE;
  964.     else
  965.         lite_spot(yy, xx);
  966.     (void)mmove(dir, &yy, &xx);
  967.     }
  968.     while (!flag);
  969. }
  970.  
  971.  
  972. /* Light line in all directions                -RAK-     */
  973. void 
  974. starlite(y, x)
  975.     register int        y, x;
  976. {
  977.     register int        i;
  978.  
  979.     if (py.flags.blind < 1)
  980.     msg_print("The end of the staff bursts into a blue shimmering light.");
  981.     for (i = 1; i <= 9; i++)
  982.     if (i != 5)
  983.         light_line(i, y, x);
  984. }
  985.  
  986. /* Disarms all traps/chests in a given direction    -RAK-     */
  987. int 
  988. disarm_all(dir, y, x)
  989.     int                 dir, y, x;
  990. {
  991.     register cave_type *c_ptr;
  992.     register inven_type *t_ptr;
  993.     register int        disarm, dist;
  994.  
  995.     disarm = FALSE;
  996.     dist = (-1);
  997.     do {
  998.     /* put mmove at end, in case standing on a trap */
  999.     dist++;
  1000.     c_ptr = &cave[y][x];
  1001.     /*
  1002.      * note, must continue upto and including the first non open space,
  1003.      * because secret doors have fval greater than MAX_OPEN_SPACE 
  1004.      */
  1005.     if (c_ptr->tptr != 0) {
  1006.         t_ptr = &t_list[c_ptr->tptr];
  1007.         if ((t_ptr->tval == TV_INVIS_TRAP) || (t_ptr->tval == TV_VIS_TRAP)) {
  1008.         if (delete_object(y, x))
  1009.             disarm = TRUE;
  1010.         } else if (t_ptr->tval == TV_CLOSED_DOOR)
  1011.         t_ptr->p1 = 0;       /* Locked or jammed doors become merely
  1012.                     * closed. */
  1013.         else if (t_ptr->tval == TV_SECRET_DOOR) {
  1014.         c_ptr->fm = TRUE;
  1015.         change_trap(y, x);
  1016.         disarm = TRUE;
  1017.         } else if ((t_ptr->tval == TV_CHEST) && (t_ptr->flags != 0)) {
  1018.         msg_print("Click!");
  1019.         t_ptr->flags &= ~(CH_TRAPPED | CH_LOCKED);
  1020.         disarm = TRUE;
  1021.         t_ptr->name2 = SN_UNLOCKED;
  1022.         known2(t_ptr);
  1023.         }
  1024.     }
  1025.     (void)mmove(dir, &y, &x);
  1026.     }
  1027.     while ((dist <= OBJ_BOLT_RANGE) && c_ptr->fval <= MAX_OPEN_SPACE);
  1028.     return (disarm);
  1029. }
  1030.  
  1031.  
  1032. /* Shoot a bolt in a given direction            -RAK-     */
  1033. void 
  1034. fire_bolt(typ, dir, y, x, dam_hp, bolt_typ)
  1035.     int                 typ, dir, y, x, dam_hp;
  1036.     const char               *bolt_typ;
  1037. {
  1038.     int                 i, oldy, oldx, dist, flag;
  1039. /*    int32u              harm_type = 0; */
  1040.     register cave_type *c_ptr;
  1041.     register monster_type *m_ptr;
  1042.     register creature_type *r_ptr;
  1043.     vtype               out_val, m_name;
  1044.     int                 dam = dam_hp;
  1045.     int                 ny, nx;
  1046.     char                bolt_char;
  1047.  
  1048.     flag = FALSE;
  1049.     oldy = y;
  1050.     oldx = x;
  1051.     dist = 0;
  1052.     do {
  1053.     ny = y;
  1054.     nx = x;
  1055.     (void)mmove(dir, &y, &x);
  1056.     /* choose the right shape for the bolt... -CFT */
  1057.     if (ny == y)
  1058.         bolt_char = '-';
  1059.     else if (nx == x)
  1060.         bolt_char = '|';
  1061.     else if ((ny - y) == (nx - x))
  1062.         bolt_char = '\\';
  1063.     else
  1064.         bolt_char = '/';
  1065.  
  1066.     dist++;
  1067.     c_ptr = &cave[y][x];
  1068.     lite_spot(oldy, oldx);
  1069.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  1070.         flag = TRUE;
  1071.     else {
  1072.         if (c_ptr->cptr > 1) {
  1073.         flag = TRUE;
  1074.         m_ptr = &m_list[c_ptr->cptr];
  1075.         r_ptr = &c_list[m_ptr->mptr];
  1076.         /*
  1077.          * light up monster and draw monster, temporarily set pl so that
  1078.          * update_mon() will work 
  1079.          */
  1080.         i = c_ptr->pl;
  1081.         c_ptr->pl = TRUE;
  1082.         update_mon((int)c_ptr->cptr);
  1083.         c_ptr->pl = i;
  1084.         /* draw monster and clear previous bolt */
  1085.         put_qio();
  1086.  
  1087.         spell_hit_monster(m_ptr, typ, &dam, 0, &ny, &nx);
  1088.         c_ptr = &cave[ny][nx];    /* may be new location if teleported
  1089.                      * by gravity warp... */
  1090.         m_ptr = &m_list[c_ptr->cptr];    /* and even if not, may be
  1091.                          * new monster if chaos
  1092.                          * polymorphed */
  1093.         r_ptr = &c_list[m_ptr->mptr];
  1094.         monster_name(m_name, m_ptr, r_ptr);
  1095.         i = mon_take_hit((int)c_ptr->cptr, dam, TRUE);
  1096.  
  1097.         if (i >= 0) {
  1098.             if ((r_ptr->cdefense & (DEMON|UNDEAD|MINDLESS)) ||
  1099.             (r_ptr->cchar == 'E') ||
  1100.             (r_ptr->cchar == 'v') ||
  1101.             (r_ptr->cchar == 'g'))
  1102.             (void)sprintf(out_val, "%s is destroyed.",
  1103.                       m_name);
  1104.             else
  1105.             (void)sprintf(out_val, "%s dies in a fit of agony.",
  1106.                       m_name);
  1107.             msg_print(out_val);
  1108.             prt_experience();
  1109.         } else if (dam > 0) {
  1110.             (void)sprintf(out_val,
  1111.                    pain_message((int)c_ptr->cptr, dam), m_name);
  1112.             msg_print(out_val);
  1113.         }
  1114.         } else if (panel_contains(y, x) && (py.flags.blind < 1)) {
  1115.         print(bolt_char, y, x);
  1116.         /* show the bolt */
  1117.         put_qio();
  1118. #ifdef MSDOS
  1119.         delay(8 * delay_spd);    /* milliseconds */
  1120. #else
  1121.         usleep(8000 * delay_spd);    /* useconds */
  1122. #endif
  1123.         }
  1124.     }
  1125.     oldy = y;
  1126.     oldx = x;
  1127. #ifdef TARGET
  1128.     if (target_mode && at_target(y,x))
  1129.         flag = TRUE; /* must have hit "targeted" area -CFT */
  1130. #endif
  1131.     }
  1132.     while (!flag);
  1133.     lite_spot(oldy, oldx);       /* just in case, clear any leftover bolt
  1134.                     * images -CFT */
  1135. }
  1136.  
  1137.  
  1138. /* Shoot a bolt in a given direction                    -RAK-   */
  1139. /* heavily modified to include exotic bolts -CFT */
  1140. void 
  1141. bolt(typ, y, x, dam_hp, ddesc, ptr, monptr)
  1142.     int                 typ, y, x, dam_hp;
  1143.     char               *ddesc;
  1144.     monster_type       *ptr;
  1145.     int                 monptr;
  1146. {
  1147.     int                 i = ptr->fy, j = ptr->fx;
  1148.     int                 dam;
  1149.     int32u              tmp, treas;
  1150.     register cave_type *c_ptr;
  1151.     register monster_type *m_ptr;
  1152.     register creature_type *r_ptr;
  1153.     char                bolt_char;
  1154.     int                 blind = (py.flags.status & PY_BLIND) ? 1 : 0;
  1155.     int                 ny, nx, sourcey, sourcex, dist;
  1156.     vtype               m_name, out_val;
  1157.  
  1158.     sourcey = i;
  1159.     sourcex = j;
  1160.     dist = 0;
  1161.     do {
  1162.     /* This is going along a badly angled line so call mmove2 direct */
  1163.     ny = i;
  1164.     nx = j;
  1165.     mmove2(&i, &j, sourcey, sourcex, char_row, char_col);
  1166.     dist++;
  1167.  
  1168.     /* choose the right shape for the bolt... -CFT */
  1169.     if (ny == i)
  1170.         bolt_char = '-';
  1171.     else if (nx == j)
  1172.         bolt_char = '|';
  1173.     else if ((ny - i) == (nx - j))
  1174.         bolt_char = '\\';
  1175.     else
  1176.         bolt_char = '/';
  1177.  
  1178.     if (in_bounds(i, j) && los(y, x, i, j)) {
  1179.         c_ptr = &cave[i][j];
  1180.         if (c_ptr->fval <= MAX_OPEN_SPACE) {
  1181.         if (panel_contains(i, j) && !(py.flags.status & PY_BLIND)) {
  1182.             print(bolt_char, i, j);
  1183.             put_qio();
  1184. #ifdef MSDOS
  1185.             delay(8 * delay_spd);    /* milliseconds */
  1186. #else
  1187.             usleep(8000 * delay_spd);    /* useconds */
  1188. #endif
  1189.             lite_spot(i, j);
  1190.         }
  1191.         if (c_ptr->cptr > 1 && c_ptr->cptr != monptr) {
  1192.             m_ptr = &m_list[c_ptr->cptr];
  1193.             dam = dam_hp;
  1194.  
  1195.             spell_hit_monster(m_ptr, typ, &dam, 0, &ny, &nx);
  1196.                 /* process hit effects */
  1197.             c_ptr = &cave[ny][nx];    /* may be new location if
  1198.                          * teleported by gravity
  1199.                          * warp... */
  1200.             m_ptr = &m_list[c_ptr->cptr];    /* and even if not, may
  1201.                              * be new monster if
  1202.                              * chaos polymorphed */
  1203.             r_ptr = &c_list[m_ptr->mptr];
  1204.             monster_name(m_name, m_ptr, r_ptr);
  1205.  
  1206.             if (dam < 1)
  1207.             dam = 1;   /* protect vs neg damage -CFT */
  1208.             m_ptr->hp = m_ptr->hp - dam;
  1209.             m_ptr->csleep = 0;
  1210.             if ((r_ptr->cdefense & UNIQUE) && (m_ptr->hp < 0))
  1211.             m_ptr->hp = 0;    /* prevent unique monster from death
  1212.                      * by other monsters.  It causes
  1213.                      * trouble (monster not marked as
  1214.                      * dead, quest monsters don't satisfy
  1215.                      * quest, etc).  So, we let then
  1216.                      * live, but extremely wimpy. -CFT */
  1217.             if (m_ptr->hp < 0) {
  1218.             if ((r_ptr->cdefense & (DEMON|UNDEAD|MINDLESS)) ||
  1219.                 (r_ptr->cchar == 'E') ||
  1220.                 (r_ptr->cchar == 'v') ||
  1221.                 (r_ptr->cchar == 'g'))
  1222.                 (void)sprintf(out_val, "%s is destroyed.",
  1223.                       m_name);
  1224.             else
  1225.                 (void)sprintf(out_val, "%s dies in a fit of agony.",
  1226.                       m_name);
  1227.             msg_print(out_val);
  1228.             object_level = (dun_level + r_ptr->level) >> 1;
  1229.             treas = monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  1230.                           r_ptr->cmove, 0, 0);
  1231.             if (m_ptr->ml || (c_list[m_ptr->mptr].cdefense & UNIQUE)) {
  1232.                 tmp = (c_recall[m_ptr->mptr].r_cmove & CM_TREASURE)
  1233.                 >> CM_TR_SHIFT;
  1234.                 if (tmp > ((treas & CM_TREASURE) >> CM_TR_SHIFT))
  1235.                 treas = (treas & ~CM_TREASURE) | (tmp << CM_TR_SHIFT);
  1236.                 c_recall[m_ptr->mptr].r_cmove = treas |
  1237.                 (c_recall[m_ptr->mptr].r_cmove & ~CM_TREASURE);
  1238.             }
  1239.             if (monptr < c_ptr->cptr)
  1240.                 delete_monster((int)c_ptr->cptr);
  1241.             else
  1242.                 fix1_delete_monster((int)c_ptr->cptr);
  1243.             } else {
  1244.             (void)sprintf(out_val, pain_message((int)c_ptr->cptr, dam),
  1245.                       m_name);
  1246.             msg_print(out_val);
  1247.             }
  1248.             break;
  1249.         } else if (c_ptr->cptr == 1) {
  1250.             if (dam_hp < 1)
  1251.             dam_hp = 1;
  1252.             m_ptr = &m_list[monptr];
  1253.             switch (typ) {
  1254.               case GF_LIGHTNING:
  1255.             if (blind)
  1256.                 msg_print("You are hit by electricity!");
  1257.             light_dam(dam_hp, ddesc);
  1258.             break;
  1259.               case GF_POISON_GAS:
  1260.             if (blind)
  1261.                 msg_print("You are hit by a blast of noxious gases!");
  1262.             poison_gas(dam_hp, ddesc);
  1263.             break;
  1264.               case GF_ACID:
  1265.             if (blind)
  1266.                 msg_print("You are hit by a jet of acidic fluid!");
  1267.             acid_dam(dam_hp, ddesc);
  1268.             break;
  1269.               case GF_FROST:
  1270.             if (blind)
  1271.                 msg_print("You are hit by something cold!");
  1272.             cold_dam(dam_hp, ddesc);
  1273.             break;
  1274.               case GF_FIRE:
  1275.             if (blind)
  1276.                 msg_print("You are hit by something hot!");
  1277.             fire_dam(dam_hp, ddesc);
  1278.             break;
  1279.               case GF_MAGIC_MISSILE:
  1280.             if (blind)
  1281.                 msg_print("You are hit by something!");
  1282.             take_hit(dam_hp, ddesc);
  1283.             break;
  1284.               case GF_HOLY_ORB:
  1285.             if (blind)
  1286.                 msg_print("You are hit by something!");
  1287.             dam_hp /= 2;    /* player should take less damage
  1288.                      * -CFT */
  1289.             take_hit(dam_hp, ddesc);
  1290.             break;
  1291.               case GF_ARROW:    /* maybe can miss? */
  1292.             if (blind)
  1293.                 msg_print("You are hit by something!");
  1294.             take_hit(dam_hp, ddesc);
  1295.             break;
  1296.               case GF_PLASMA:    /* no resist to plasma? */
  1297.             if (blind)
  1298.                 msg_print("You are hit by something!");
  1299.             take_hit(dam_hp, ddesc);
  1300.             break;
  1301.               case GF_NETHER:
  1302.             if (blind)
  1303.                 msg_print("You are hit by an unholy blast!");
  1304.             if (py.flags.nether_resist) {
  1305.                 dam_hp *= 6;    /* these 2 lines give avg dam
  1306.                          * of .655, ranging from */
  1307.                 dam_hp /= (randint(6) + 6);    /* .858 to .5 -CFT */
  1308.             } else {   /* no resist */
  1309.                 if (py.flags.hold_life && randint(5) > 1)
  1310.                 msg_print("You keep hold of your life force!");
  1311.                 else if (py.flags.hold_life) {
  1312.                 msg_print("You feel your life slipping away!");
  1313.                 lose_exp(200 + (py.misc.exp / 1000) * MON_DRAIN_LIFE);
  1314.                 } else {
  1315.                 msg_print("You feel your life draining away!");
  1316.                 lose_exp(200 + (py.misc.exp / 100) * MON_DRAIN_LIFE);
  1317.                 }
  1318.             }
  1319.             take_hit(dam_hp, ddesc);
  1320.             break;
  1321.               case GF_WATER:
  1322.             if (blind)
  1323.                 msg_print("You are hit by a jet of water!");
  1324.             if (!py.flags.sound_resist)
  1325.                 stun_player(randint(15));
  1326.             take_hit(dam_hp, ddesc);
  1327.             break;
  1328.               case GF_CHAOS:
  1329.             if (blind)
  1330.                 msg_print("You are hit by wave of entropy!");
  1331.             if (py.flags.chaos_resist) {
  1332.                 dam_hp *= 6;    /* these 2 lines give avg dam
  1333.                          * of .655, ranging from */
  1334.                 dam_hp /= (randint(6) + 6);    /* .858 to .5 -CFT */
  1335.             }
  1336.             if ((!py.flags.confusion_resist) && (!py.flags.chaos_resist)) {
  1337.                 if (py.flags.confused > 0)
  1338.                 py.flags.confused += 12;
  1339.                 else
  1340.                 py.flags.confused = randint(20) + 10;
  1341.             }
  1342.             if (!py.flags.chaos_resist)
  1343.                 py.flags.image += randint(10);
  1344.             take_hit(dam_hp, ddesc);
  1345.             break;
  1346.               case GF_SHARDS:
  1347.             if (blind)
  1348.                 msg_print("You are cut by sharp fragments!");
  1349.             if (py.flags.shards_resist) {
  1350.                 dam_hp *= 6;    /* these 2 lines give avg dam
  1351.                          * of .655, ranging from */
  1352.                 dam_hp /= (randint(6) + 6);    /* .858 to .5 -CFT */
  1353.             } else {
  1354.                 cut_player(dam_hp);    /* ouch! */
  1355.             }
  1356.             take_hit(dam_hp, ddesc);
  1357.             break;
  1358.               case GF_SOUND:
  1359.             if (blind)
  1360.                 msg_print("You are deafened by a blast of noise!");
  1361.             if (py.flags.sound_resist) {
  1362.                 dam_hp *= 5;
  1363.                 dam_hp /= (randint(6) + 6);
  1364.             } else {
  1365.                 stun_player(randint((dam_hp > 60) ? 25 : (dam_hp / 3 + 5)));
  1366.             }
  1367.             take_hit(dam_hp, ddesc);
  1368.             break;
  1369.               case GF_CONFUSION:
  1370.             if (blind)
  1371.                 msg_print("You are hit by a wave of dizziness!");
  1372.             if (py.flags.confusion_resist) {
  1373.                 dam_hp *= 5;
  1374.                 dam_hp /= (randint(6) + 6);
  1375.             }
  1376.             if (!py.flags.confusion_resist && !py.flags.chaos_resist) {
  1377.                 if (py.flags.confused > 0)
  1378.                 py.flags.confused += 8;
  1379.                 else
  1380.                 py.flags.confused = randint(15) + 5;
  1381.             }
  1382.             take_hit(dam_hp, ddesc);
  1383.             break;
  1384.               case GF_DISENCHANT:
  1385.             if (blind)
  1386.                 msg_print("You are hit by something!");
  1387.             if (py.flags.disenchant_resist) {
  1388.                 dam_hp *= 6;    /* these 2 lines give avg dam
  1389.                          * of .655, ranging from */
  1390.                 dam_hp /= (randint(6) + 6);    /* .858 to .5 -CFT */
  1391.             } else {
  1392.                 int8u               disenchant = FALSE;
  1393.                 int8u               chance;
  1394.                 int                 t = 0;
  1395.                 inven_type         *i_ptr;
  1396.  
  1397.                 switch (randint(7)) {
  1398.                   case 1:
  1399.                 t = INVEN_BODY;
  1400.                 break;
  1401.                   case 2:
  1402.                 t = INVEN_BODY;
  1403.                 break;
  1404.                   case 3:
  1405.                 t = INVEN_ARM;
  1406.                 break;
  1407.                   case 4:
  1408.                 t = INVEN_OUTER;
  1409.                 break;
  1410.                   case 5:
  1411.                 t = INVEN_HANDS;
  1412.                 break;
  1413.                   case 6:
  1414.                 t = INVEN_HEAD;
  1415.                 break;
  1416.                   case 7:
  1417.                 t = INVEN_FEET;
  1418.                 break;
  1419.                 }
  1420.                 i_ptr = &inventory[t];
  1421.                 chance = 1;
  1422.                 if (i_ptr->flags2 & TR_ARTIFACT)    /* Artifacts have 2/3 */
  1423.                 chance = randint(3);    /* chance to resist -DGK */
  1424.                 if ((i_ptr->tohit > 0) && (chance == 1)) {
  1425.                 i_ptr->tohit -= randint(2);
  1426.                 /* don't send it below zero */
  1427.                 if (i_ptr->tohit < 0)
  1428.                     i_ptr->tohit = 0;
  1429.                 disenchant = TRUE;
  1430.                 }
  1431.                 if ((i_ptr->todam > 0) && (chance == 1)) {
  1432.                 i_ptr->todam -= randint(2);
  1433.                 /* don't send it below zero */
  1434.                 if (i_ptr->todam < 0)
  1435.                     i_ptr->todam = 0;
  1436.                 disenchant = TRUE;
  1437.                 }
  1438.                 if ((i_ptr->toac > 0) && (chance == 1)) {
  1439.                 i_ptr->toac -= randint(2);
  1440.                 /* don't send it below zero */
  1441.                 if (i_ptr->toac < 0)
  1442.                     i_ptr->toac = 0;
  1443.                 disenchant = TRUE;
  1444.                 }
  1445.                 if (disenchant || (chance != 1)) {
  1446.                 vtype               t1, t2;
  1447.  
  1448.                 objdes(t1, &inventory[t], FALSE);
  1449.                 if (chance != 1)
  1450.                     sprintf(t2, "Your %s (%c) %s disenchanted!", t1,
  1451.                         i + 'a' - INVEN_WIELD,
  1452.                         (inventory[i].number != 1) ? "were" : "was");
  1453.                 else
  1454.                     sprintf(t2, "Your %s (%c) %s disenchantment!", t1,
  1455.                         i + 'a' - INVEN_WIELD,
  1456.                         (inventory[i].number != 1) ?
  1457.                         "resist" : "resists");
  1458.                 msg_print(t2);
  1459.                 calc_bonuses();
  1460.                 }
  1461.             }
  1462.             take_hit(dam_hp, ddesc);
  1463.             break;
  1464.               case GF_NEXUS:    /* no spec. effects from nexus bolt,
  1465.                      * only breath -CFT */
  1466.             if (blind)
  1467.                 msg_print("You are hit by something strange!");
  1468.             if (py.flags.nexus_resist) {
  1469.                 dam_hp *= 6;    /* these 2 lines give avg dam
  1470.                          * of .655, ranging from */
  1471.                 dam_hp /= (randint(6) + 6);    /* .858 to .5 -CFT */
  1472.             }
  1473.             take_hit(dam_hp, ddesc);
  1474.             break;
  1475.               case GF_FORCE:
  1476.             if (blind)
  1477.                 msg_print("You are hit hard by a sudden force!");
  1478.             if (!py.flags.sound_resist)
  1479.                 stun_player(randint(15) + 1);
  1480.             take_hit(dam_hp, ddesc);
  1481.             break;
  1482.               case GF_INERTIA:
  1483.             if (blind)
  1484.                 msg_print("You are hit by something!");
  1485.             if ((py.flags.slow > 0) && (py.flags.slow < 32000))
  1486.                 py.flags.slow += randint(5);
  1487.             else {
  1488.                 msg_print("You feel less able to move.");
  1489.                 py.flags.slow = randint(5) + 3;
  1490.             }
  1491.             take_hit(dam_hp, ddesc);
  1492.             break;
  1493.               case GF_LIGHT:
  1494.             if (blind)
  1495.                 msg_print("You are hit by something!");
  1496.             if (py.flags.light_resist) {
  1497.                 dam_hp *= 4;    /* these 2 lines give avg dam
  1498.                          * of .444, ranging from */
  1499.                 dam_hp /= (randint(6) + 6);    /* .556 to .333 -CFT */
  1500.             } else if (!blind && !py.flags.blindness_resist) {
  1501.                 msg_print("You are blinded by the flash!");
  1502.                 py.flags.blind += randint(5) + 2;
  1503.             }
  1504.             take_hit(dam_hp, ddesc);
  1505.             break;
  1506.               case GF_DARK:
  1507.             if (blind)
  1508.                 msg_print("You are hit by something!");
  1509.             if (py.flags.dark_resist) {
  1510.                 dam_hp *= 4;    /* these 2 lines give avg dam
  1511.                          * of .444, ranging from */
  1512.                 dam_hp /= (randint(6) + 6);    /* .556 to .333 -CFT */
  1513.             } else {
  1514.                 if (!blind) 
  1515.                 msg_print("The darkness prevents you from seeing!");
  1516.                 py.flags.blind += randint(5) + 2;
  1517.             }
  1518.             take_hit(dam_hp, ddesc);
  1519.             break;
  1520.               case GF_TIME:    /* only some effects from time bolt
  1521.                      * -CFT */
  1522.             if (blind)
  1523.                 msg_print("You are hit by something!");
  1524.             if (randint(2) == 1) {
  1525.                 msg_print("You feel life has clocked back.");
  1526.                 lose_exp(m_ptr->hp + (py.misc.exp / 300) * MON_DRAIN_LIFE);
  1527.             } else {
  1528.                 int                 t = 0;
  1529.  
  1530.                 switch (randint(6)) {
  1531.                   case 1:
  1532.                 t = A_STR;
  1533.                 msg_print("You're not as strong as you used to be...");
  1534.                 break;
  1535.                   case 2:
  1536.                 t = A_INT;
  1537.                 msg_print("You're not as bright as you used to be...");
  1538.                 break;
  1539.                   case 3:
  1540.                 t = A_WIS;
  1541.                 msg_print("You're not as wise as you used to be...");
  1542.                 break;
  1543.                   case 4:
  1544.                 t = A_DEX;
  1545.                 msg_print("You're not as agile as you used to be...");
  1546.                 break;
  1547.                   case 5:
  1548.                 t = A_CON;
  1549.                 msg_print("You're not as hale as you used to be...");
  1550.                 break;
  1551.                   case 6:
  1552.                 t = A_CHR;
  1553.                 msg_print("You're not as beautiful as you used to be...");
  1554.                 break;
  1555.                 }
  1556.                 py.stats.cur_stat[t] = (py.stats.cur_stat[t] * 3) / 4;
  1557.                 if (py.stats.cur_stat[t] < 3)
  1558.                 py.stats.cur_stat[t] = 3;
  1559.                 set_use_stat(t);
  1560.                 prt_stat(t);
  1561.             }
  1562.             take_hit(dam_hp, ddesc);
  1563.             break;
  1564.               case GF_GRAVITY:
  1565.             if (blind)
  1566.                 msg_print("You are hit by a surge of gravity!");
  1567.             if ((!py.flags.sound_resist) && (!py.flags.ffall))    /* DGK */
  1568.                 stun_player(randint(15) + 1);
  1569.             if (py.flags.ffall) {    /* DGK */
  1570.                 dam_hp *= 3;    /* these 2 lines give avg dam
  1571.                          * of .25, ranging from */
  1572.                 dam_hp /= (randint(6) + 6);    /* .427 to .25 -CFT */
  1573.             } else {   /* DGK */
  1574.                 if ((py.flags.slow > 0) && (py.flags.slow < 32000))
  1575.                 py.flags.slow += randint(5);
  1576.                 else {
  1577.                 msg_print("You feel less able to move.");
  1578.                 py.flags.slow = randint(5) + 3;
  1579.                 }
  1580.             } /* DGK */
  1581.             take_hit(dam_hp, ddesc);
  1582.             break;
  1583.               case GF_MANA:
  1584.             if (blind)
  1585.                 msg_print("You are hit by a beam of power!");
  1586.             take_hit(dam_hp, ddesc);
  1587.             break;
  1588.               case GF_METEOR:
  1589.             if (blind)
  1590.                 msg_print("You are hit by something!");
  1591.             take_hit(dam_hp, ddesc);
  1592.             break;
  1593.               case GF_ICE:
  1594.             if (blind)
  1595.                 msg_print("You are hit by something cold and sharp!");
  1596.             cold_dam(dam_hp, ddesc);
  1597.             if (!py.flags.sound_resist)
  1598.                 stun_player(randint(15) + 1);
  1599.             if (!py.flags.shards_resist)
  1600.                 cut_player(damroll(8, 10));
  1601.             break;
  1602.               default:
  1603.             msg_print("Unknown typ in bolt().  This may mean trouble.");
  1604.             }
  1605.             disturb(1, 0);
  1606.             break;
  1607.         }
  1608.         }
  1609.     }
  1610.     } while ((i != char_row) || (j != char_col));
  1611. }
  1612.  
  1613. /* Shoot a ball in a given direction.  Note that balls have an  */
  1614. /* area affect.                                       -RAK-   */
  1615. void 
  1616. fire_ball(typ, dir, y, x, dam_hp, max_dis, descrip)
  1617.     int                 typ, dir, y, x, dam_hp, max_dis;
  1618.     const char          *descrip;
  1619. {
  1620.     register int        i, j;
  1621.     int                 dam, thit, tkill, k, tmp, monptr;
  1622.     int                 oldy, oldx, dist, flag;
  1623.     int                 (*destroy) ();
  1624.     register cave_type *c_ptr;
  1625.     register monster_type *m_ptr;
  1626.     register creature_type *r_ptr;
  1627.     int                 ny, nx;
  1628.     char                bolt_char;
  1629.  
  1630.     thit = 0;
  1631.     tkill = 0;
  1632.  
  1633.     ball_destroy(typ, &destroy);
  1634.  
  1635.     flag = FALSE;
  1636.     oldy = y;
  1637.     oldx = x;
  1638.     dist = 0;
  1639.     do {
  1640.     ny = y;
  1641.     nx = x;
  1642.     (void)mmove(dir, &y, &x);
  1643.  
  1644.     /* choose the right shape for the bolt... -CFT */
  1645.     if (ny == y)
  1646.         bolt_char = '-';
  1647.     else if (nx == x)
  1648.         bolt_char = '|';
  1649.     else if ((ny - y) == (nx - x))
  1650.         bolt_char = '\\';
  1651.     else
  1652.         bolt_char = '/';
  1653.  
  1654.     dist++;
  1655.     lite_spot(oldy, oldx);
  1656.     if (dist > OBJ_BOLT_RANGE)
  1657.         flag = TRUE;
  1658.     else {
  1659.         c_ptr = &cave[y][x];
  1660.     /* targeting code stolen from Morgul -CFT */
  1661.  
  1662.     /*
  1663.      * This test has been overhauled (twice):  basically, it now says: if
  1664.      * ((spell hits a wall) OR ((spell hits a creature) and ((not
  1665.      * targetting) or (at the target anyway) or (no line-of-sight to
  1666.      * target, so aiming unusable) or ((aiming at a monster) and (that
  1667.      * monster is unseen, so aiming unusable)))) OR ((we are targetting)
  1668.      * and (at the target location))) THEN the ball explodes...                     
  1669.      * -CFT  
  1670.      */
  1671. #ifndef TARGET
  1672.         if ((c_ptr->fval >= MIN_CLOSED_SPACE) ||
  1673.         ((c_ptr->cptr > 1))) {
  1674.         flag = TRUE;       /* THEN we decide to explode here. -CFT */
  1675.         if (c_ptr->fval >= MIN_CLOSED_SPACE) {
  1676.             y = oldy;
  1677.             x = oldx;
  1678.         }
  1679. #else
  1680.         if ((c_ptr->fval >= MIN_CLOSED_SPACE) ||
  1681.         ((c_ptr->cptr > 1) &&
  1682.          (!target_mode || at_target(y, x) ||
  1683.           !los(target_row, target_col, char_row, char_col) ||
  1684.           ((target_mon < MAX_MALLOC) && !m_list[target_mon].ml))) ||
  1685.         (target_mode && at_target(y, x))) {
  1686.             flag = TRUE;       /* THEN we decide to explode here. -CFT */
  1687.             if (c_ptr->fval >= MIN_CLOSED_SPACE) {
  1688.             y = oldy;
  1689.             x = oldx;
  1690.             }
  1691. #endif
  1692.         /* The ball hits and explodes.               */
  1693.         /* The explosion.                            */
  1694.         for (i = y - max_dis; i <= y + max_dis; i++)
  1695.             for (j = x - max_dis; j <= x + max_dis; j++)
  1696.             if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis) &&
  1697.              los(char_row, char_col, i, j) && los(y, x, i, j) &&
  1698.                 (cave[i][j].fval <= MAX_OPEN_SPACE) &&
  1699.                 panel_contains(i, j) && (py.flags.blind < 1)) {
  1700. #ifdef TC_COLOR
  1701.                 if (!no_color_flag)
  1702.                 textcolor(bolt_color(typ));
  1703. #endif
  1704.                 print('*', i, j);
  1705. #ifdef TC_COLOR
  1706.                 if (!no_color_flag)
  1707.                 textcolor(LIGHTGRAY);    /* prob don't need here,
  1708.                              * but... -CFT */
  1709. #endif
  1710.             }
  1711.         if (py.flags.blind < 1) {
  1712.             put_qio();
  1713. #ifdef MSDOS
  1714.             delay(25 * delay_spd);    /* milliseconds */
  1715. #else
  1716.             usleep(25000 * delay_spd);    /* useconds */
  1717. #endif
  1718.         }
  1719.         /*
  1720.          * now erase the ball, since effects below may use msg_print, and
  1721.          * pause indefinitely, so we want ball gone before then -CFT 
  1722.          */
  1723.         for (i = y - max_dis; i <= y + max_dis; i++)
  1724.             for (j = x - max_dis; j <= x + max_dis; j++)
  1725.             if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis) &&
  1726.              los(char_row, char_col, i, j) && los(y, x, i, j) &&
  1727.                 (cave[i][j].fval <= MAX_OPEN_SPACE) &&
  1728.                 panel_contains(i, j) && (py.flags.blind < 1)) {
  1729.                 lite_spot(i, j);    /* draw what is below the '*' */
  1730.             }
  1731.         put_qio();
  1732.         /*
  1733.          * First go over the area of effect, and destroy items...  Any
  1734.          * preexisting items will be affected, but items dropped by
  1735.          * killed monsters are assummed to have been "shielded" from the
  1736.          * effects the the monster's corpse.  This means that you no
  1737.          * longer have to be SO paranoid about using fire/frost/acid
  1738.          * balls. -CFT 
  1739.          */
  1740.         for (i = y - max_dis; i <= y + max_dis; i++)
  1741.             for (j = x - max_dis; j <= x + max_dis; j++)
  1742.             if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis)
  1743.                 && los(y, x, i, j) && (cave[i][j].tptr != 0) &&
  1744.                 (*destroy) (&t_list[cave[i][j].tptr]))
  1745.                 (void)delete_object(i, j);    /* burn/corrode or OW
  1746.                              * destroy items in area
  1747.                              * of effect */
  1748.         /* now go over area of affect and DO something to monsters... */
  1749.         for (i = y - max_dis; i <= y + max_dis; i++)
  1750.             for (j = x - max_dis; j <= x + max_dis; j++)
  1751.             if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis)
  1752.                 && los(y, x, i, j)) {
  1753.                 c_ptr = &cave[i][j];
  1754.                 if (c_ptr->fval <= MAX_OPEN_SPACE) {
  1755.                 if (c_ptr->cptr > 1) {
  1756.                     dam = dam_hp;
  1757.                     m_ptr = &m_list[c_ptr->cptr];
  1758.                     spell_hit_monster(m_ptr, typ, &dam,
  1759.                       (distance(i, j, y, x) + 1), &ny, &nx);
  1760.                     c_ptr = &cave[ny][nx];
  1761.             /* may be new location if teleported by gravity warp... */
  1762.                     m_ptr = &m_list[c_ptr->cptr];
  1763.             /* and even if not, may be new monster if chaos polymorphed */
  1764.                     r_ptr = &c_list[m_ptr->mptr];
  1765.                     monptr = c_ptr->cptr;
  1766.  
  1767.                 /*
  1768.                  * lite up creature if visible, temp set pl
  1769.                  * so that update_mon works 
  1770.                  */
  1771.                     tmp = c_ptr->pl;
  1772.                     c_ptr->pl = TRUE;
  1773.                     update_mon((int)c_ptr->cptr);
  1774.  
  1775.                     thit++;
  1776.                     if (dam < 1)
  1777.                     dam = 1;    /* protect vs neg damage
  1778.                              * -CFT */
  1779.                     k = mon_take_hit((int)c_ptr->cptr, dam, TRUE);
  1780.                     if (k >= 0)
  1781.                     tkill++;
  1782.                     c_ptr->pl = tmp;
  1783.                 }
  1784.                 lite_spot(i, j);    /* erase the ball... */
  1785.                 }
  1786.             }
  1787.         /* show ball of whatever */
  1788.         put_qio();
  1789.  
  1790.         /* End  explosion.                   */
  1791.         if (tkill == 1) {
  1792.             msg_print("There is a scream of agony!");
  1793.         } else if (tkill > 1) {
  1794.             msg_print("There are several screams of agony!");
  1795.         }
  1796.         if (tkill >= 0)
  1797.             prt_experience();
  1798.         /* End ball hitting.                 */
  1799.         } else if (panel_contains(y, x) && (py.flags.blind < 1)) {
  1800. #ifdef TC_COLOR
  1801.         if (!no_color_flag)
  1802.             textcolor(bolt_color(typ));
  1803. #endif
  1804.         print(bolt_char, y, x);
  1805.         put_qio();
  1806. #ifdef TC_COLOR
  1807.         if (!no_color_flag)
  1808.             textcolor(LIGHTGRAY);
  1809. #endif
  1810. #ifdef MSDOS
  1811.         delay(8 * delay_spd);    /* milliseconds */
  1812. #else
  1813.         usleep(8000 * delay_spd);    /* useconds */
  1814. #endif
  1815.         }
  1816.         oldy = y;
  1817.         oldx = x;
  1818. #ifdef TARGET
  1819.         if (target_mode && at_target(y,x))
  1820.         flag = TRUE; /* must have hit "targetted" area -CFT */
  1821. #endif
  1822.     }
  1823.     } while (!flag);
  1824. }
  1825.  
  1826. /* Lightning ball in all directions                        SM   */
  1827. void 
  1828. starball(y, x)
  1829.     register int        y, x;
  1830. {
  1831.     register int        i;
  1832.  
  1833.     for (i = 1; i <= 9; i++)
  1834.     if (i != 5)
  1835.         fire_ball(GF_LIGHTNING, i, y, x, 150, 3,
  1836.               "massive storm of Electricity");
  1837. }
  1838.  
  1839. /* Breath weapon works like a fire_ball, but affects the player. */
  1840. /* Note the area affect.                              -RAK-   */
  1841. void 
  1842. breath(typ, y, x, dam_hp, ddesc, monptr)
  1843.     int                 typ, y, x, dam_hp;
  1844.     char               *ddesc;
  1845.     int                 monptr;
  1846. {
  1847.     register int        i, j;
  1848.     int                 dam, max_dis;
  1849.     int32u              tmp, treas;
  1850.     int                 (*destroy) ();
  1851.     register cave_type *c_ptr;
  1852.     register monster_type *m_ptr;
  1853.     register creature_type *r_ptr;
  1854.     int                 ny, nx;
  1855.     int                 blind = (py.flags.status & PY_BLIND) ? 1 : 0;
  1856.     char                ch;
  1857.  
  1858.     m_ptr = &m_list[monptr];
  1859.     r_ptr = &c_list[m_ptr->mptr];
  1860.     ch = r_ptr->cchar;
  1861.     if ((ch == 'v' || ch == 'D' || ch == 'E' || ch == '&' || ch == 'A') ||
  1862.     ((ch == 'd' || ch == 'R') && r_ptr->cdefense & UNIQUE))
  1863.     max_dis = 3;
  1864.     else
  1865.     max_dis = 2;
  1866.  
  1867.     ball_destroy(typ, &destroy);
  1868.  
  1869.     if (!(py.flags.status & PY_BLIND)) { /* only bother if the player can see */
  1870.     for (i = y - max_dis; i <= y + max_dis; i++)
  1871.         for (j = x - max_dis; j <= x + max_dis; j++)
  1872.         if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis) &&
  1873.             los(y, x, i, j) && (cave[i][j].fval <= MAX_OPEN_SPACE) &&
  1874.             panel_contains(i, j)) {
  1875. #ifdef TC_COLOR
  1876.             if (!no_color_flag)
  1877.             textcolor(bolt_color(typ));
  1878. #endif
  1879.             print('*', i, j);
  1880. #ifdef TC_COLOR
  1881.             if (!no_color_flag)
  1882.             textcolor(LIGHTGRAY);    /* prob don't need here,
  1883.                          * but... -CFT */
  1884. #endif
  1885.         }
  1886.     put_qio();
  1887. #ifdef MSDOS
  1888.     delay(25 * delay_spd);       /* milliseconds */
  1889. #else
  1890.     usleep(25000 * delay_spd); /* useconds */
  1891. #endif
  1892.  
  1893. /*
  1894.  * now erase the ball, since effects below may use msg_print, and pause
  1895.  * indefinitely, so we want ball gone before then -CFT 
  1896.  */
  1897.     for (i = y - max_dis; i <= y + max_dis; i++)
  1898.         for (j = x - max_dis; j <= x + max_dis; j++)
  1899.         if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis) &&
  1900.             los(y, x, i, j) && (cave[i][j].fval <= MAX_OPEN_SPACE) &&
  1901.             panel_contains(i, j))
  1902.             lite_spot(i, j);   /* draw what is below the '*' */
  1903.     put_qio();
  1904.     }
  1905. /*
  1906.  * first, go over area of affect and destroy preexisting items. This change
  1907.  * means that any treasure dropped by killed monsters is safe from the effects
  1908.  * of this ball (but not from any later balls/breathes, even if they happen
  1909.  * before the player gets a chance to pick up that scroll of *Acquirement*). 
  1910.  * The assumption is made that this treasure was shielded from the effects by
  1911.  * the corpse of the killed monster. -CFT 
  1912.  */
  1913.     for (i = y - max_dis; i <= y + max_dis; i++)
  1914.     for (j = x - max_dis; j <= x + max_dis; j++)
  1915.         if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis)
  1916.         && los(y, x, i, j) && (cave[i][j].tptr != 0)
  1917.         && (*destroy) (&t_list[cave[i][j].tptr]))
  1918.         delete_object(i, j);
  1919.  
  1920. /* now go over area of affect and DO something to monsters */
  1921.     for (i = y - max_dis; i <= y + max_dis; i++)
  1922.     for (j = x - max_dis; j <= x + max_dis; j++)
  1923.         if (in_bounds(i, j) && (distance(y, x, i, j) <= max_dis)
  1924.         && los(y, x, i, j)) {
  1925.  
  1926.         c_ptr = &cave[i][j];
  1927.         if ((c_ptr->tptr != 0) && (*destroy) (&t_list[c_ptr->tptr]))
  1928.             (void)delete_object(i, j);
  1929.         if (c_ptr->fval <= MAX_OPEN_SPACE) {
  1930.             if ((c_ptr->cptr > 1) && (c_ptr->cptr != monptr)) {
  1931.             dam = dam_hp;
  1932.             m_ptr = &m_list[c_ptr->cptr];
  1933.             spell_hit_monster(m_ptr, typ, &dam, distance(i, j, y, x) + 1,
  1934.                       &ny, &nx);
  1935.             c_ptr = &cave[ny][nx];    /* may be new location if teleported
  1936.                                                  * by gravity warp... */
  1937.             m_ptr = &m_list[c_ptr->cptr];    /* and even if not, may be new
  1938.                              * monster if chaos polymorphed */
  1939.             r_ptr = &c_list[m_ptr->mptr];
  1940.  
  1941.             /*
  1942.              * can not call mon_take_hit here, since player does not
  1943.              * get experience for kill 
  1944.              */
  1945.             if (dam < 1)
  1946.                 dam = 1;
  1947.             m_ptr->hp = m_ptr->hp - dam;
  1948.             m_ptr->csleep = 0;
  1949.             if ((r_ptr->cdefense & UNIQUE) && (m_ptr->hp < 0))
  1950.                 m_ptr->hp = 0;    /* prevent unique monster
  1951.                          * from death by other
  1952.                          * monsters.  It causes
  1953.                          * trouble (monster not
  1954.                          * marked as dead, quest
  1955.                          * monsters don't satisfy
  1956.                          * quest, etc).  So, we let
  1957.                          * then live, but extremely
  1958.                          * wimpy.  This isn't great,
  1959.                          * because monster might heal
  1960.                          * itself before player's
  1961.                          * next swing... -CFT */
  1962.             if (m_ptr->hp < 0) {
  1963.                 object_level = (dun_level + r_ptr->level) >> 1;
  1964.                 treas = monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  1965.                           r_ptr->cmove, 0, 0);
  1966.                 /* recall even invisible uniques -CWS */
  1967.                 if (m_ptr->ml || (c_list[m_ptr->mptr].cdefense & UNIQUE)) {
  1968.                 tmp = (c_recall[m_ptr->mptr].r_cmove & CM_TREASURE)
  1969.                     >> CM_TR_SHIFT;
  1970.                 if (tmp > ((treas & CM_TREASURE) >> CM_TR_SHIFT))
  1971.                     treas = (treas & ~CM_TREASURE) | (tmp << CM_TR_SHIFT);
  1972.                 c_recall[m_ptr->mptr].r_cmove = treas |
  1973.                     (c_recall[m_ptr->mptr].r_cmove & ~CM_TREASURE);
  1974.                 }
  1975.             /*
  1976.              * It ate an already processed monster.Handle
  1977.              * normally. 
  1978.              */
  1979.                 if (monptr < c_ptr->cptr)
  1980.                 delete_monster((int)c_ptr->cptr);
  1981.             /*
  1982.              * If it eats this monster, an already processed
  1983.              * monster will take its place, causing all kinds of
  1984.              * havoc. Delay the kill a bit. 
  1985.              */
  1986.                 else
  1987.                 fix1_delete_monster((int)c_ptr->cptr);
  1988.             }
  1989.             } else if (c_ptr->cptr == 1) {
  1990.             dam = (dam_hp / (distance(i, j, y, x) + 1));
  1991.             m_ptr = &m_list[monptr];
  1992.             /* let's do at least one point of damage */
  1993.             /* prevents randint(0) problem with poison_gas, also */
  1994.             if (dam <= 0)
  1995.                 dam = 1;
  1996.             if (dam > 1600)
  1997.                 dam = 1600;
  1998.             switch (typ) {
  1999.               case GF_LIGHTNING:
  2000.                 light_dam(dam, ddesc);
  2001.                 break;
  2002.               case GF_POISON_GAS:
  2003.                 poison_gas(dam, ddesc);
  2004.                 break;
  2005.               case GF_ACID:
  2006.                 acid_dam(dam, ddesc);
  2007.                 break;
  2008.               case GF_FROST:
  2009.                 cold_dam(dam, ddesc);
  2010.                 break;
  2011.               case GF_FIRE:
  2012.                 fire_dam(dam, ddesc);
  2013.                 break;
  2014.               case GF_MAGIC_MISSILE:
  2015.                 take_hit(dam, ddesc);
  2016.                 break;
  2017.               case GF_HOLY_ORB:
  2018.                 dam /= 2;    /* player should take less damage
  2019.                      * from "good" power-CFT */
  2020.                 take_hit(dam, ddesc);
  2021.                 break;
  2022.               case GF_ARROW:    /* maybe can miss? */
  2023.                 take_hit(dam, ddesc);
  2024.                 break;
  2025.               case GF_PLASMA:    /* no resist to plasma? */
  2026.                 take_hit(dam, ddesc);
  2027.                 if (!py.flags.sound_resist)
  2028.                 stun_player(randint(
  2029.                 (dam_hp > 40) ? 35 : (dam_hp * 3 / 4 + 5)));
  2030.                 break;
  2031.               case GF_NETHER:
  2032.                 if (py.flags.nether_resist) {
  2033.                 dam *= 6;    /* these 2 lines give avg dam
  2034.                          * of .655, ranging from */
  2035.                 dam /= (randint(5) + 6);    /* .858 to .5 -CFT */
  2036.                 } else {    /* no resist */
  2037.                 if (py.flags.hold_life && randint(3) > 1)
  2038.                     msg_print("You keep hold of your life force!");
  2039.                 else if (py.flags.hold_life) {
  2040.                     msg_print("You feel your life slipping away!");
  2041.                     lose_exp(200 + (py.misc.exp/1000) * MON_DRAIN_LIFE);
  2042.                 } else {
  2043.                     msg_print("You feel your life draining away!");
  2044.                     lose_exp(200 + (py.misc.exp/100) * MON_DRAIN_LIFE);
  2045.                 }
  2046.                 }
  2047.                 take_hit(dam, ddesc);
  2048.                 break;
  2049.               case GF_WATER:
  2050.                 if (!py.flags.sound_resist)
  2051.                 stun_player(randint(55));
  2052.                 if (!player_saves() && !py.flags.confusion_resist
  2053.                 && !py.flags.chaos_resist) {
  2054.                 if ((py.flags.confused > 0) &&
  2055.                     (py.flags.confused < 32000))
  2056.                     py.flags.confused += 6;
  2057.                 else
  2058.                     py.flags.confused = randint(8) + 6;
  2059.                 }
  2060.                 take_hit(dam, ddesc);
  2061.                 break;
  2062.               case GF_CHAOS:
  2063.                 if (py.flags.chaos_resist) {
  2064.                 dam *= 6;    /* these 2 lines give avg dam
  2065.                          * of .655, ranging from */
  2066.                 dam /= (randint(6) + 6);    /* .858 to .5 -CFT */
  2067.                 }
  2068.                 if ((!py.flags.confusion_resist) &&
  2069.                 (!py.flags.chaos_resist)) {
  2070.                 if (py.flags.confused > 0)
  2071.                     py.flags.confused += 12;
  2072.                 else
  2073.                     py.flags.confused = randint(20) + 10;
  2074.                 }
  2075.                 if (!py.flags.chaos_resist)
  2076.                 py.flags.image += randint(10);
  2077.                 if (!py.flags.nether_resist && !py.flags.chaos_resist) {
  2078.                 if (py.flags.hold_life && randint(3) > 1)
  2079.                     msg_print("You keep hold of your life force!");
  2080.                 else if (py.flags.hold_life) {
  2081.                     msg_print("You feel your life slipping away!");
  2082.                     lose_exp(500 + (py.misc.exp/1000) * MON_DRAIN_LIFE);
  2083.                 } else {
  2084.                     msg_print("You feel your life draining away!");
  2085.                     lose_exp(5000 + (py.misc.exp/100) * MON_DRAIN_LIFE);
  2086.                 }
  2087.                 }
  2088.                 take_hit(dam, ddesc);
  2089.                 break;
  2090.               case GF_SHARDS:
  2091.                 if (py.flags.shards_resist) {
  2092.                 dam *= 6;    /* these 2 lines give avg dam
  2093.                          * of .655, ranging from */
  2094.                 dam /= (randint(6) + 6);    /* .858 to .5 -CFT */
  2095.                 } else {
  2096.                 cut_player(dam);    /* ouch! */
  2097.                 }
  2098.                 take_hit(dam, ddesc);
  2099.                 break;
  2100.               case GF_SOUND:
  2101.                 if (py.flags.sound_resist) {
  2102.                 dam *= 5;
  2103.                 dam /= (randint(6) + 6);
  2104.                 } else {
  2105.                 stun_player(randint((dam > 90) ? 35 : (dam / 3 + 5)));
  2106.                 }
  2107.                 take_hit(dam, ddesc);
  2108.                 break;
  2109.               case GF_CONFUSION:
  2110.                 if (py.flags.confusion_resist) {
  2111.                 dam *= 5;    /* these 2 lines give avg dam
  2112.                          * of .655, ranging from */
  2113.                 dam /= (randint(6) + 6);    /* .858 to .5 -CFT */
  2114.                 }
  2115.                 if (!py.flags.confusion_resist && !py.flags.chaos_resist) {
  2116.                 if (py.flags.confused > 0)
  2117.                     py.flags.confused += 12;
  2118.                 else
  2119.                     py.flags.confused = randint(20) + 10;
  2120.                 }
  2121.                 take_hit(dam, ddesc);
  2122.                 break;
  2123.               case GF_DISENCHANT:
  2124.                 if (py.flags.disenchant_resist) {
  2125.                 dam *= 6;    /* these 2 lines give avg dam
  2126.                          * of .655, ranging from */
  2127.                 dam /= (randint(6) + 6);    /* .858 to .5 -CFT */
  2128.                 } else {
  2129.                 int8u               disenchant = FALSE;
  2130.                 int8u               chance;
  2131.                 int                 t = 0;
  2132.                 inven_type         *i_ptr;
  2133.  
  2134.                 switch (randint(7)) {
  2135.                   case 1:
  2136.                     t = INVEN_BODY;
  2137.                     break;
  2138.                   case 2:
  2139.                     t = INVEN_BODY;
  2140.                     break;
  2141.                   case 3:
  2142.                     t = INVEN_ARM;
  2143.                     break;
  2144.                   case 4:
  2145.                     t = INVEN_OUTER;
  2146.                     break;
  2147.                   case 5:
  2148.                     t = INVEN_HANDS;
  2149.                     break;
  2150.                   case 6:
  2151.                     t = INVEN_HEAD;
  2152.                     break;
  2153.                   case 7:
  2154.                     t = INVEN_FEET;
  2155.                     break;
  2156.                 }
  2157.                 i_ptr = &inventory[t];
  2158.                 chance = 1;
  2159.                 /* Artifacts have 2/3 chance to resist -DGK */
  2160.                 if (i_ptr->flags2 & TR_ARTIFACT)
  2161.                     chance = randint(3);
  2162.                 if ((i_ptr->tohit > 0) && (chance == 1)) {
  2163.                     i_ptr->tohit -= randint(2);
  2164.                 /* don't send it below zero */
  2165.                     if (i_ptr->tohit < 0)
  2166.                     i_ptr->tohit = 0;
  2167.                     disenchant = TRUE;
  2168.                 }
  2169.                 if ((i_ptr->todam > 0) && (chance == 1)) {
  2170.                     i_ptr->todam -= randint(2);
  2171.                 /* don't send it below zero */
  2172.                     if (i_ptr->todam < 0)
  2173.                     i_ptr->todam = 0;
  2174.                     disenchant = TRUE;
  2175.                 }
  2176.                 if ((i_ptr->toac > 0) && (chance == 1)) {
  2177.                     i_ptr->toac -= randint(2);
  2178.                 /* don't send it below zero */
  2179.                     if (i_ptr->toac < 0)
  2180.                     i_ptr->toac = 0;
  2181.                     disenchant = TRUE;
  2182.                 }
  2183.                 if (disenchant || (chance != 1)) {
  2184.                     vtype               t1, t2;
  2185.  
  2186.                     objdes(t1, &inventory[t], FALSE);
  2187.                     if (chance != 1)
  2188.                     sprintf(t2, "Your %s (%c) %s disenchanted!", t1,
  2189.                         i + 'a' - INVEN_WIELD,
  2190.                         (inventory[i].number != 1) ?
  2191.                         "were" : "was");
  2192.                     else
  2193.                     sprintf(t2, "Your %s (%c) %s disenchantment!",
  2194.                         t1,
  2195.                         i + 'a' - INVEN_WIELD,
  2196.                         (inventory[i].number != 1) ?
  2197.                         "resist" : "resists");
  2198.                     msg_print(t2);
  2199.                     calc_bonuses();
  2200.                 }
  2201.                 }
  2202.                 take_hit(dam, ddesc);
  2203.                 break;
  2204.               case GF_NEXUS:    /* no spec. effects from
  2205.                          * nexus bolt, only breath
  2206.                          * -CFT */
  2207.                 if (py.flags.nexus_resist) {
  2208.                 dam *= 6;    /* these 2 lines give avg dam
  2209.                          * of .655, ranging from */
  2210.                 dam /= (randint(6) + 6);    /* .858 to .5 -CFT */
  2211.                 } else {    /* special effects */
  2212.                 switch (randint(7)) {
  2213.                   case 1:
  2214.                   case 2:
  2215.                   case 3:
  2216.                     teleport(200);
  2217.                     break;
  2218.                   case 4:
  2219.                   case 5:
  2220.                     teleport_to((int)m_ptr->fy, (int)m_ptr->fx);
  2221.                     break;
  2222.                   case 6:
  2223.                     if (player_saves())
  2224.                     msg_print("You resist the effects.");
  2225.                     else {
  2226.                     int                 k = dun_level;
  2227.  
  2228.                     if (dun_level == Q_PLANE)
  2229.                         dun_level = 0;
  2230.                     else if (is_quest(dun_level))
  2231.                         dun_level -= 1;
  2232.                     else
  2233.                         dun_level += (-3) + 2 * randint(2);
  2234.                     if (dun_level < 0)
  2235.                         dun_level = 0;
  2236.                     if (k == Q_PLANE)
  2237.                 msg_print("You warp through a cross-dimension gate.");
  2238.                     else if (k < dun_level)
  2239.                         msg_print("You sink through the floor.");
  2240.                     else
  2241.                     msg_print("You rise up through the ceiling.");
  2242.                     new_level_flag = TRUE;
  2243.                     }
  2244.                     break;
  2245.                   case 7:
  2246.                     if (player_saves() && randint(2) == 1)
  2247.                     msg_print("You resist the effects.");
  2248.                     else {
  2249.                     int      max1, cur1, max2, cur2, ii, jj;
  2250.  
  2251.                     msg_print("Your body starts to scramble...");
  2252.                     ii = randint(6) - 1;
  2253.                     do {
  2254.                         jj = randint(6) - 1;
  2255.                     } while (ii == jj);
  2256.                     max1 = py.stats.max_stat[ii];
  2257.                     cur1 = py.stats.cur_stat[ii];
  2258.                     max2 = py.stats.max_stat[jj];
  2259.                     cur2 = py.stats.cur_stat[jj];
  2260.                     py.stats.max_stat[ii] = max2;
  2261.                     py.stats.cur_stat[ii] = cur2;
  2262.                     py.stats.max_stat[jj] = max1;
  2263.                     py.stats.cur_stat[jj] = cur1;
  2264.                     set_use_stat(ii);
  2265.                     set_use_stat(jj);
  2266.                     prt_stat(ii);
  2267.                     prt_stat(jj);
  2268.                     }
  2269.                 } /* switch for effects */
  2270.                 }
  2271.                 take_hit(dam, ddesc);
  2272.                 break;
  2273.               case GF_FORCE:
  2274.                 if (!py.flags.sound_resist)
  2275.                 stun_player(randint(20));
  2276.                 take_hit(dam, ddesc);
  2277.                 break;
  2278.               case GF_INERTIA:
  2279.                 if ((py.flags.slow > 0) && (py.flags.slow < 32000))
  2280.                 py.flags.slow += randint(5);
  2281.                 else {
  2282.                 msg_print("You feel less able to move.");
  2283.                 py.flags.slow = randint(5) + 3;
  2284.                 }
  2285.                 take_hit(dam, ddesc);
  2286.                 break;
  2287.               case GF_LIGHT:
  2288.                 if (py.flags.light_resist) {
  2289.                 dam *= 4;
  2290.                 dam /= (randint(6) + 6);
  2291.                 } else if (!blind && !py.flags.blindness_resist) {
  2292.                 msg_print("You are blinded by the flash!");
  2293.                 py.flags.blind += randint(6) + 3;
  2294.                 }
  2295.                 light_area(char_row, char_col, 0, max_dis);
  2296.                 take_hit(dam, ddesc);
  2297.                 break;
  2298.               case GF_DARK:
  2299.                 if (py.flags.dark_resist) {
  2300.                 dam *= 4;
  2301.                 dam /= (randint(6) + 6);
  2302.                 } else {
  2303.                 if (!blind) 
  2304.                     msg_print("The darkness prevents you from seeing!");
  2305.                 py.flags.blind += randint(5) + 2;
  2306.                 }
  2307.                 unlight_area(char_row, char_col);
  2308.                 take_hit(dam, ddesc);
  2309.                 break;
  2310.               case GF_TIME:    /* only some effects from
  2311.                          * time bolt -CFT */
  2312.                 switch (randint(10)) {
  2313.                   case 1:
  2314.                   case 2:
  2315.                   case 3:
  2316.                   case 4:
  2317.                   case 5:
  2318.                 msg_print("You feel life has clocked back.");
  2319.                 lose_exp(m_ptr->hp + (py.misc.exp / 300) * MON_DRAIN_LIFE);
  2320.                 break;
  2321.                   case 6:
  2322.                   case 7:
  2323.                   case 8:
  2324.                   case 9:
  2325.                 {
  2326.                     int                 t = 0;
  2327.  
  2328.                     switch (randint(6)) {
  2329.                       case 1:
  2330.                     t = A_STR;
  2331.                 msg_print("You're not as strong as you used to be...");
  2332.                     break;
  2333.                       case 2:
  2334.                     t = A_INT;
  2335.                 msg_print("You're not as bright as you used to be...");
  2336.                     break;
  2337.                       case 3:
  2338.                     t = A_WIS;
  2339.                 msg_print("You're not as wise as you used to be...");
  2340.                     break;
  2341.                       case 4:
  2342.                     t = A_DEX;
  2343.                 msg_print("You're not as agile as you used to be...");
  2344.                     break;
  2345.                       case 5:
  2346.                     t = A_CON;
  2347.                 msg_print("You're not as hale as you used to be...");
  2348.                     break;
  2349.                       case 6:
  2350.                     t = A_CHR;
  2351.             msg_print("You're not as beautiful as you used to be...");
  2352.                     break;
  2353.                     }
  2354.                 py.stats.cur_stat[t] = (py.stats.cur_stat[t] * 3) / 4;
  2355.                     if (py.stats.cur_stat[t] < 3)
  2356.                     py.stats.cur_stat[t] = 3;
  2357.                     set_use_stat(t);
  2358.                     prt_stat(t);
  2359.                 }
  2360.                 break;
  2361.                   case 10:
  2362.                 {
  2363.                     int                 ii;
  2364.  
  2365.                     for (ii = 0; ii < 6; ii++) {
  2366.                 py.stats.cur_stat[ii] = (py.stats.cur_stat[ii] * 3) / 4;
  2367.                     if (py.stats.cur_stat[ii] < 3)
  2368.                         py.stats.cur_stat[ii] = 3;
  2369.                     set_use_stat(ii);
  2370.                     prt_stat(ii);
  2371.                     }
  2372.                 }
  2373.                 msg_print("You're not as strong as you used to be...");
  2374.                 msg_print("You're not as bright as you used to be...");
  2375.                 msg_print("You're not as wise as you used to be...");
  2376.                 msg_print("You're not as agile as you used to be...");
  2377.                 msg_print("You're not as hale as you used to be...");
  2378.             msg_print("You're not as beautiful as you used to be...");
  2379.                 break;
  2380.                 } /* randint(10) for effects */
  2381.                 take_hit(dam, ddesc);
  2382.                 break;
  2383.               case GF_GRAVITY:
  2384.                 if ((!py.flags.sound_resist) && (!py.flags.ffall))    /* DGK */
  2385.                 stun_player(randint((dam > 90) ? 35 : (dam / 3 + 5)));
  2386.                 if (py.flags.ffall) {    /* DGK */
  2387.                 dam_hp *= 3;    /* these 2 lines give avg dam
  2388.                          * of .33, ranging from */
  2389.                 dam_hp /= (randint(6) + 6);    /* .427 to .25 -CFT */
  2390.                 } else {    /* DGK */
  2391.                 if ((py.flags.slow > 0) && (py.flags.slow < 32000))
  2392.                     py.flags.slow += randint(5);
  2393.                 else {
  2394.                     msg_print("You feel less able to move.");
  2395.                     py.flags.slow = randint(5) + 3;
  2396.                 }
  2397.                 } /* DGK */
  2398.                 msg_print("Gravity warps around you.");
  2399.                 teleport(5);
  2400.                 take_hit(dam, ddesc);
  2401.                 break;
  2402.               case GF_MANA:
  2403.                 take_hit(dam, ddesc);
  2404.                 break;
  2405.               case GF_METEOR:
  2406.                 take_hit(dam, ddesc);
  2407.                 break;
  2408.               case GF_ICE:
  2409.                 cold_dam(dam, ddesc);
  2410.                 if (!py.flags.sound_resist)
  2411.                 stun_player(randint(25));
  2412.                 if (!py.flags.shards_resist)
  2413.                 cut_player(damroll(8, 10));
  2414.                 break;
  2415.               default:
  2416.             msg_print("Unknown typ in breath().  This may mean trouble.");
  2417.             }
  2418.             }
  2419.         }
  2420.         }
  2421. /* show the ball of gas */
  2422.     put_qio();
  2423.  
  2424. /* erase ball and redraw */
  2425.     for (i = (y - max_dis); i <= (y + max_dis); i++)
  2426.     for (j = (x - max_dis); j <= (x + max_dis); j++)
  2427.         if (in_bounds(i, j) && panel_contains(i, j) &&
  2428.         (distance(y, x, i, j) <= max_dis))
  2429.         lite_spot(i, j);
  2430. }
  2431.  
  2432.  
  2433. int 
  2434. recharge(num)
  2435.     register int        num;
  2436. {
  2437.     int                 i, j, k, l, item_val;
  2438.     register int        res;
  2439.     register inven_type *i_ptr;
  2440.     int                 found = FALSE;
  2441.  
  2442.     res = FALSE;
  2443.     if (find_range(TV_STAFF, TV_WAND, &i, &j))
  2444.     found = TRUE;
  2445.     if (find_range(TV_ROD, TV_NEVER, &k, &l))
  2446.     found = TRUE;
  2447.  
  2448.     if (!found)
  2449.     msg_print("You have nothing to recharge.");
  2450.     else if (get_item(&item_val, "Recharge which item?",
  2451.               (k > -1) ? k : i, (j > -1) ? j : l, 0)) {
  2452.     i_ptr = &inventory[item_val];
  2453.     res = TRUE;
  2454.     if (i_ptr->tval == TV_ROD) {    /* now allow players to speed up
  2455.                      * recharge time of rods -CFT */
  2456.         int16u              t_o = i_ptr->timeout, t;
  2457.  
  2458.         if (randint((100 - i_ptr->level + num) / 5) == 1) {    /* not today... */
  2459.         msg_print("The recharge backfires, and drains the rod further!");
  2460.         if (t_o < 32000)   /* don't overflow... */
  2461.             i_ptr->timeout = (t_o + 100) * 2;
  2462.         } else {
  2463.         t = (int16u) (num * damroll(2, 4));    /* rechange amount */
  2464.         if (t_o < t)
  2465.             i_ptr->timeout = 0;
  2466.         else
  2467.             i_ptr->timeout = t_o - t;
  2468.         }
  2469.     }
  2470.      /* if recharge rod... */ 
  2471.     else {               /* recharge wand/staff */
  2472.     /* recharge I = recharge(20) = 1/6 failure for empty 10th level wand */
  2473.     /*
  2474.      * recharge II = recharge(60) = 1/10 failure for empty 10th level
  2475.      * wand 
  2476.      */
  2477.     /* make it harder to recharge high level, and highly charged wands */
  2478.         if (randint((num + 100 - (int)i_ptr->level - (10 * i_ptr->p1)) / 15) == 1) {
  2479.         msg_print("There is a bright flash of light.");
  2480.         inven_destroy(item_val);
  2481.         } else {
  2482.         num = (num / (i_ptr->level + 2)) + 1;
  2483.         i_ptr->p1 += 2 + randint(num);
  2484.         if (known2_p(i_ptr))
  2485.             clear_known2(i_ptr);
  2486.         clear_empty(i_ptr);
  2487.         }
  2488.     }
  2489.     }
  2490.     return (res);
  2491. }
  2492.  
  2493. /* Increase or decrease a creatures hit points        -RAK-     */
  2494. int 
  2495. hp_monster(dir, y, x, dam)
  2496.     int                 dir, y, x, dam;
  2497. {
  2498.     register int        i;
  2499.     int                 flag, dist, monster;
  2500.     register cave_type *c_ptr;
  2501.     register monster_type *m_ptr;
  2502.     register creature_type *r_ptr;
  2503.     vtype               out_val, m_name;
  2504.  
  2505.     monster = FALSE;
  2506.     flag = FALSE;
  2507.     dist = 0;
  2508.     do {
  2509.     (void)mmove(dir, &y, &x);
  2510.     dist++;
  2511.     c_ptr = &cave[y][x];
  2512.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2513.         flag = TRUE;
  2514.     else if (c_ptr->cptr > 1) {
  2515.         flag = TRUE;
  2516.         m_ptr = &m_list[c_ptr->cptr];
  2517.         r_ptr = &c_list[m_ptr->mptr];
  2518.         monster_name(m_name, m_ptr, r_ptr);
  2519.         monster = TRUE;
  2520.         i = mon_take_hit((int)c_ptr->cptr, dam, TRUE);
  2521.         if (i >= 0) {
  2522.         (void)sprintf(out_val, "%s dies in a fit of agony.", m_name);
  2523.         msg_print(out_val);
  2524.         prt_experience();
  2525.         } else if (dam > 0) {
  2526.         (void)sprintf(out_val,
  2527.                   pain_message((int)c_ptr->cptr, dam), m_name);
  2528.         msg_print(out_val);
  2529.         }
  2530.     }
  2531.     }
  2532.     while (!flag);
  2533.     return (monster);
  2534. }
  2535.  
  2536.  
  2537. /* Drains life; note it must be living.        -RAK-     */
  2538. int 
  2539. drain_life(dir, y, x, dam)
  2540.     int                 dir, y, x, dam;
  2541. {
  2542.     register int        i;
  2543.     int                 flag, dist, drain;
  2544.     register cave_type *c_ptr;
  2545.     register monster_type *m_ptr;
  2546.     register creature_type *r_ptr;
  2547.     vtype               out_val, m_name;
  2548.  
  2549.     drain = FALSE;
  2550.     flag = FALSE;
  2551.     dist = 0;
  2552.     do {
  2553.     (void)mmove(dir, &y, &x);
  2554.     dist++;
  2555.     c_ptr = &cave[y][x];
  2556.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2557.         flag = TRUE;
  2558.     else if (c_ptr->cptr > 1) {
  2559.         flag = TRUE;
  2560.         m_ptr = &m_list[c_ptr->cptr];
  2561.         r_ptr = &c_list[m_ptr->mptr];
  2562.         if (((r_ptr->cdefense & UNDEAD) == 0) &&
  2563.         ((r_ptr->cdefense & DEMON) == 0) &&
  2564.         (r_ptr->cchar != 'E' && r_ptr->cchar != 'g' && r_ptr->cchar != 'v')) {
  2565.         drain = TRUE;
  2566.         monster_name(m_name, m_ptr, r_ptr);
  2567.         i = mon_take_hit((int)c_ptr->cptr, dam, TRUE);
  2568.         if (i >= 0) {
  2569.             (void)sprintf(out_val, "%s dies in a fit of agony.", m_name);
  2570.             msg_print(out_val);
  2571.             prt_experience();
  2572.         } else {
  2573.             (void)sprintf(out_val,
  2574.                    pain_message((int)c_ptr->cptr, dam), m_name);
  2575.             msg_print(out_val);
  2576.         }
  2577.         } else {
  2578.         if (r_ptr->cdefense & UNDEAD)
  2579.             c_recall[m_ptr->mptr].r_cdefense |= UNDEAD;
  2580.         else
  2581.             c_recall[m_ptr->mptr].r_cdefense |= DEMON;
  2582.         }
  2583.     }
  2584.     }
  2585.     while (!flag);
  2586.     return (drain);
  2587. }
  2588.  
  2589.  
  2590. /* Increase or decrease a creatures speed        -RAK-     */
  2591. /* NOTE: cannot slow a winning creature (BALROG)         */
  2592. int 
  2593. speed_monster(dir, y, x, spd)
  2594.     int                 dir, y, x, spd;
  2595. {
  2596.     int                 flag, dist, speed;
  2597.     register cave_type *c_ptr;
  2598.     register monster_type *m_ptr;
  2599.     register creature_type *r_ptr;
  2600.     vtype               out_val, m_name;
  2601.  
  2602.     speed = FALSE;
  2603.     flag = FALSE;
  2604.     dist = 0;
  2605.     do {
  2606.     (void)mmove(dir, &y, &x);
  2607.     dist++;
  2608.     c_ptr = &cave[y][x];
  2609.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2610.         flag = TRUE;
  2611.     else if (c_ptr->cptr > 1) {
  2612.         flag = TRUE;
  2613.         m_ptr = &m_list[c_ptr->cptr];
  2614.         r_ptr = &c_list[m_ptr->mptr];
  2615.         monster_name(m_name, m_ptr, r_ptr);
  2616.         if (spd > 0) {
  2617.         m_ptr->cspeed += spd;
  2618.         m_ptr->csleep = 0;
  2619.         (void)sprintf(out_val, "%s starts moving faster.", m_name);
  2620.         msg_print(out_val);
  2621.         speed = TRUE;
  2622.         } else if ((r_ptr->level >
  2623.             randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  2624.                (r_ptr->cdefense & UNIQUE)) {
  2625.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  2626.         msg_print(out_val);
  2627.         m_ptr->csleep = 0;
  2628.         } else {
  2629.         m_ptr->cspeed += spd;
  2630.         m_ptr->csleep = 0;
  2631.         (void)sprintf(out_val, "%s starts moving slower.", m_name);
  2632.         msg_print(out_val);
  2633.         speed = TRUE;
  2634.         }
  2635.     }
  2636.     }
  2637.     while (!flag);
  2638.     return (speed);
  2639. }
  2640.  
  2641.  
  2642. /* Confuse a creature                    -RAK-     */
  2643. int 
  2644. confuse_monster(dir, y, x, lvl)
  2645.     int                 dir, y, x, lvl;
  2646. {
  2647.     int                 flag, dist, confuse;
  2648.     register cave_type *c_ptr;
  2649.     register monster_type *m_ptr;
  2650.     register creature_type *r_ptr;
  2651.     vtype               out_val, m_name;
  2652.  
  2653.     confuse = FALSE;
  2654.     flag = FALSE;
  2655.     dist = 0;
  2656.     do {
  2657.     (void)mmove(dir, &y, &x);
  2658.     dist++;
  2659.     c_ptr = &cave[y][x];
  2660.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2661.         flag = TRUE;
  2662.     else if (c_ptr->cptr > 1) {
  2663.         m_ptr = &m_list[c_ptr->cptr];
  2664.         r_ptr = &c_list[m_ptr->mptr];
  2665.         monster_name(m_name, m_ptr, r_ptr);
  2666.         flag = TRUE;
  2667.         if ((r_ptr->level >
  2668.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  2669.         (r_ptr->cdefense & UNIQUE ||
  2670.          r_ptr->spells2 & (BREATH_CO | BREATH_CH))) {
  2671.         if (m_ptr->ml && (r_ptr->cdefense & CHARM_SLEEP))
  2672.             c_recall[m_ptr->mptr].r_cdefense |= CHARM_SLEEP;
  2673.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  2674.         msg_print(out_val);
  2675.         m_ptr->csleep = 0;
  2676.         } else {
  2677.         if (m_ptr->confused < 175)
  2678.             m_ptr->confused += (int8u) (damroll(3, (lvl / 2)) + 1);
  2679.         confuse = TRUE;
  2680.         m_ptr->csleep = 0;
  2681.         (void)sprintf(out_val, "%s appears confused.", m_name);
  2682.         msg_print(out_val);
  2683.         }
  2684.     }
  2685.     }
  2686.     while (!flag);
  2687.     return (confuse);
  2688. }
  2689.  
  2690.  
  2691. /* Scare a creature -DGK */
  2692. int 
  2693. fear_monster(dir, y, x, lvl)
  2694.     int                 dir, y, x, lvl;
  2695. {
  2696.     int                 flag, dist, fear;
  2697.     register cave_type *c_ptr;
  2698.     register monster_type *m_ptr;
  2699.     register creature_type *r_ptr;
  2700.     vtype               out_val, m_name;
  2701.  
  2702.     fear = FALSE;
  2703.     flag = FALSE;
  2704.     dist = 0;
  2705.     do {
  2706.     (void)mmove(dir, &y, &x);
  2707.     dist++;
  2708.     c_ptr = &cave[y][x];
  2709.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2710.         flag = TRUE;
  2711.     else if (c_ptr->cptr > 1) {
  2712.         m_ptr = &m_list[c_ptr->cptr];
  2713.         r_ptr = &c_list[m_ptr->mptr];
  2714.         monster_name(m_name, m_ptr, r_ptr);
  2715.         flag = TRUE;
  2716.         if ((r_ptr->level >
  2717.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  2718.         (r_ptr->cdefense & UNIQUE)) {
  2719.         if (m_ptr->ml && (r_ptr->cdefense & CHARM_SLEEP))
  2720.             c_recall[m_ptr->mptr].r_cdefense |= CHARM_SLEEP;
  2721.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  2722.         msg_print(out_val);
  2723.         m_ptr->csleep = 0;
  2724.         } else {
  2725.         if (m_ptr->monfear < 175)
  2726.             m_ptr->monfear += (int8u) (damroll(3, (lvl / 2)) + 1);
  2727.         fear = TRUE;
  2728.         m_ptr->csleep = 0;
  2729.         (void)sprintf(out_val, "%s flees in terror!", m_name);
  2730.         msg_print(out_val);
  2731.         }
  2732.     }
  2733.     }
  2734.     while (!flag);
  2735.     return (fear);
  2736. }
  2737.  
  2738. /* Sleep a creature.                    -RAK-     */
  2739. int 
  2740. sleep_monster(dir, y, x)
  2741.     int                 dir, y, x;
  2742. {
  2743.     int                 flag, dist, sleep;
  2744.     register cave_type *c_ptr;
  2745.     register monster_type *m_ptr;
  2746.     register creature_type *r_ptr;
  2747.     vtype               out_val, m_name;
  2748.  
  2749.     sleep = FALSE;
  2750.     flag = FALSE;
  2751.     dist = 0;
  2752.     do {
  2753.     (void)mmove(dir, &y, &x);
  2754.     dist++;
  2755.     c_ptr = &cave[y][x];
  2756.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2757.         flag = TRUE;
  2758.     else if (c_ptr->cptr > 1) {
  2759.         m_ptr = &m_list[c_ptr->cptr];
  2760.         r_ptr = &c_list[m_ptr->mptr];
  2761.  
  2762.  
  2763.  
  2764.         flag = TRUE;
  2765.         monster_name(m_name, m_ptr, r_ptr);
  2766.         if ((r_ptr->level >
  2767.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  2768.         (r_ptr->cdefense & UNIQUE) || (r_ptr->cdefense & CHARM_SLEEP)) {
  2769.         if (m_ptr->ml && (r_ptr->cdefense & CHARM_SLEEP))
  2770.             c_recall[m_ptr->mptr].r_cdefense |= CHARM_SLEEP;
  2771.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  2772.         msg_print(out_val);
  2773.         } else {
  2774.         m_ptr->csleep = 500;
  2775.         sleep = TRUE;
  2776.         (void)sprintf(out_val, "%s falls asleep.", m_name);
  2777.         msg_print(out_val);
  2778.         }
  2779.     }
  2780.     }
  2781.     while (!flag);
  2782.     return (sleep);
  2783. }
  2784.  
  2785.  
  2786. /* Turn stone to mud, delete wall.            -RAK-     */
  2787. int 
  2788. wall_to_mud(dir, y, x)
  2789.     int                 dir, y, x;
  2790. {
  2791.     int                 i, wall, dist;
  2792.     bigvtype            out_val, tmp_str;
  2793.     register int        flag;
  2794.     register cave_type *c_ptr;
  2795.     register monster_type *m_ptr;
  2796.     register creature_type *r_ptr;
  2797.     vtype               m_name;
  2798.  
  2799.     wall = FALSE;
  2800.     flag = FALSE;
  2801.     dist = 0;
  2802.     do {
  2803.     (void)mmove(dir, &y, &x);
  2804.     dist++;
  2805.     c_ptr = &cave[y][x];
  2806.     /* note, this ray can move through walls as it turns them to mud */
  2807.     if (dist == OBJ_BOLT_RANGE)
  2808.         flag = TRUE;
  2809.     if (c_ptr->fval == BOUNDARY_WALL) {
  2810.         flag = TRUE;
  2811.         if (test_light(y, x))
  2812.         msg_print("The wall resists your spell.");
  2813.     } else if ((c_ptr->fval >= MIN_CAVE_WALL)) {
  2814.         flag = TRUE;
  2815.         (void)twall(y, x, 1, 0);
  2816.         if (test_light(y, x)) {
  2817.         msg_print("The wall turns into mud.");
  2818.         check_view();
  2819.         wall = TRUE;
  2820.         }
  2821.     } else if ((c_ptr->tptr != 0) && (c_ptr->fval >= MIN_CLOSED_SPACE)) {
  2822.         flag = TRUE;
  2823.         if (panel_contains(y, x) && test_light(y, x)) {
  2824.         objdes(tmp_str, &t_list[c_ptr->tptr], FALSE);
  2825.         (void)sprintf(out_val, "The %s turns into mud.", tmp_str);
  2826.         msg_print(out_val);
  2827.         wall = TRUE;
  2828.         }
  2829.         (void)delete_object(y, x);
  2830.         check_view();
  2831.     }
  2832.     if (c_ptr->cptr > 1) {
  2833.         m_ptr = &m_list[c_ptr->cptr];
  2834.         r_ptr = &c_list[m_ptr->mptr];
  2835.         if (HURT_ROCK & r_ptr->cdefense) {
  2836.         monster_name(m_name, m_ptr, r_ptr);
  2837.         flag = m_ptr->ml;
  2838.         i = mon_take_hit((int)c_ptr->cptr, (20 + randint(30)), TRUE);
  2839.         if (flag) {
  2840.             if (i >= 0) {
  2841.             c_recall[i].r_cdefense |= HURT_ROCK;
  2842.             (void)sprintf(out_val, "%s dissolves!", m_name);
  2843.             msg_print(out_val);
  2844.             prt_experience();    /* print msg before calling
  2845.                          * prt_exp */
  2846.             } else {
  2847.             c_recall[m_ptr->mptr].r_cdefense |= HURT_ROCK;
  2848.             (void)sprintf(out_val, "%s grunts in pain!", m_name);
  2849.             msg_print(out_val);
  2850.             }
  2851.         }
  2852.         flag = TRUE;
  2853.         }
  2854.     }
  2855.     }
  2856.     while (!flag);
  2857.     return (wall);
  2858. }
  2859.  
  2860.  
  2861. /* Destroy all traps and doors in a given direction    -RAK-     */
  2862. int 
  2863. td_destroy2(dir, y, x)
  2864.     int                 dir, y, x;
  2865. {
  2866.     register int        destroy2, dist;
  2867.     register cave_type *c_ptr;
  2868.     register inven_type *t_ptr;
  2869.  
  2870.     destroy2 = FALSE;
  2871.     dist = 0;
  2872.     do {
  2873.     (void)mmove(dir, &y, &x);
  2874.     dist++;
  2875.     c_ptr = &cave[y][x];
  2876.     /* must move into first closed spot, as it might be a secret door */
  2877.     if (c_ptr->tptr != 0) {
  2878.         t_ptr = &t_list[c_ptr->tptr];
  2879.         if (t_ptr->tval == TV_CHEST) /* let's untrap it instead -CWS */
  2880.         t_ptr->flags &= ~(CH_TRAPPED | CH_LOCKED);
  2881.         else if ((t_ptr->tval == TV_INVIS_TRAP) || (t_ptr->tval == TV_VIS_TRAP) ||
  2882.              (t_ptr->tval == TV_OPEN_DOOR) || (t_ptr->tval == TV_CLOSED_DOOR)
  2883.              || (t_ptr->tval == TV_SECRET_DOOR)) {
  2884.         if (delete_object(y, x)) {
  2885.             msg_print("There is a bright flash of light!");
  2886.             destroy2 = TRUE;
  2887.         }
  2888.         }
  2889.     }
  2890.     }
  2891.     while ((dist <= OBJ_BOLT_RANGE) || c_ptr->fval <= MAX_OPEN_SPACE);
  2892.     return (destroy2);
  2893. }
  2894.  
  2895.  
  2896. /* Polymorph a monster                    -RAK-     */
  2897. /* NOTE: cannot polymorph a unique creature                     */
  2898. int 
  2899. poly_monster(dir, y, x)
  2900.     int                 dir, y, x;
  2901. {
  2902.     int                 dist, flag, poly;
  2903.     register cave_type *c_ptr;
  2904.     register creature_type *r_ptr;
  2905.     register monster_type *m_ptr;
  2906.     vtype               out_val, m_name;
  2907.     int                 i, j, k;
  2908.  
  2909.     poly = FALSE;
  2910.     flag = FALSE;
  2911.     dist = 0;
  2912.     do {
  2913.     (void)mmove(dir, &y, &x);
  2914.     dist++;
  2915.     c_ptr = &cave[y][x];
  2916.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2917.         flag = TRUE;
  2918.     else if (c_ptr->cptr > 1) {
  2919.         m_ptr = &m_list[c_ptr->cptr];
  2920.         r_ptr = &c_list[m_ptr->mptr];
  2921.         if ((r_ptr->level <
  2922.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) &&
  2923.         !(r_ptr->cdefense & UNIQUE)) {
  2924.         i = (randint(20) / randint(9)) + 1;
  2925.         j = r_ptr->level - i;    /* get range of levels... */
  2926.         k = r_ptr->level + i;
  2927.         if (j < 0)
  2928.             j = 0;
  2929.         if (k > MAX_MONS_LEVEL)
  2930.             k = MAX_MONS_LEVEL;
  2931.         delete_monster(cave[y][x].cptr);
  2932.         do {
  2933.             i = randint(m_level[k] - m_level[j]) - 1 + m_level[j];
  2934.         /* monster index */
  2935.             if ((c_list[i].cdefense & UNIQUE) == 0)
  2936.             place_monster(y, x, i, FALSE);
  2937.         } while (cave[y][x].cptr <= MIN_MONIX);
  2938.         /* don't test c_ptr->fm here, only pl/tl */
  2939.         if (panel_contains(y, x) && (c_ptr->tl || c_ptr->pl))
  2940.             poly = TRUE;
  2941.         } else {
  2942.         monster_name(m_name, m_ptr, r_ptr);
  2943.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  2944.         msg_print(out_val);
  2945.         }
  2946.     }
  2947.     }
  2948.     while (!flag);
  2949.     return (poly);
  2950. }
  2951.  
  2952.  
  2953. /* Create a wall.                    -RAK-     */
  2954. int 
  2955. build_wall(dir, y, x)
  2956.     int                 dir, y, x;
  2957. {
  2958.     register int        i;
  2959.     int                 build, damage, dist, flag;
  2960.     register cave_type *c_ptr;
  2961.     register monster_type *m_ptr;
  2962.     register creature_type *r_ptr;
  2963.     vtype               m_name, out_val;
  2964.  
  2965.     build = FALSE;
  2966.     dist = 0;
  2967.     flag = FALSE;
  2968.     do {
  2969.     (void)mmove(dir, &y, &x);
  2970.     dist++;
  2971.     c_ptr = &cave[y][x];
  2972.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  2973.         flag = TRUE;
  2974.     else {
  2975.         if (c_ptr->cptr > 1) {
  2976.         /* stop the wall building */
  2977.         flag = TRUE;
  2978.         m_ptr = &m_list[c_ptr->cptr];
  2979.         r_ptr = &c_list[m_ptr->mptr];
  2980.  
  2981.         if (!(r_ptr->cmove & CM_PHASE)) {
  2982.         /* monster does not move, can't escape the wall */
  2983.             if (r_ptr->cmove & CM_ATTACK_ONLY)
  2984.             damage = 32000;    /* this will kill everything */
  2985.             else
  2986.             damage = damroll(4, 8);
  2987.  
  2988.             monster_name(m_name, m_ptr, r_ptr);
  2989.             (void)sprintf(out_val, "%s wails out in pain!", m_name);
  2990.             msg_print(out_val);
  2991.             i = mon_take_hit((int)c_ptr->cptr, damage, TRUE);
  2992.             if (i >= 0) {
  2993.             (void)sprintf(out_val, "%s is embedded in the rock.",
  2994.                       m_name);
  2995.             msg_print(out_val);
  2996.             /* prt_experience(); */
  2997.             }
  2998.         } else if (r_ptr->cchar == 'E' || r_ptr->cchar == 'X') {
  2999.         /*
  3000.          * must be an earth elemental or an earth spirit, or a Xorn
  3001.          * increase its hit points 
  3002.          */
  3003.             m_ptr->hp += damroll(4, 8);
  3004.         }
  3005.         }
  3006.         if (c_ptr->tptr != 0)
  3007.         if (((t_list[c_ptr->tptr].tval >= TV_MIN_WEAR) &&
  3008.              (t_list[c_ptr->tptr].tval <= TV_MAX_WEAR) &&
  3009.              (t_list[c_ptr->tptr].flags2 & TR_ARTIFACT))
  3010.             || (t_list[c_ptr->tptr].tval == TV_UP_STAIR)
  3011.             || (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR)
  3012.             || (t_list[c_ptr->tptr].tval == TV_STORE_DOOR))
  3013.             continue;       /* don't bury the artifact/stair/store */
  3014.         else
  3015.             (void)delete_object(y, x);
  3016.         c_ptr->fval = MAGMA_WALL;
  3017.         c_ptr->fm = FALSE;
  3018.         lite_spot(y, x);
  3019.         i++;
  3020.         build = TRUE;
  3021.     }
  3022.     }
  3023.     while (!flag);
  3024.     return (build);
  3025. }
  3026.  
  3027.  
  3028. /* Replicate a creature                    -RAK-     */
  3029. int 
  3030. clone_monster(dir, y, x)
  3031.     int                 dir, y, x;
  3032. {
  3033.     register cave_type *c_ptr;
  3034.     register int        dist, flag;
  3035.  
  3036.     dist = 0;
  3037.     flag = FALSE;
  3038.     do {
  3039.     (void)mmove(dir, &y, &x);
  3040.     dist++;
  3041.     c_ptr = &cave[y][x];
  3042.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  3043.         flag = TRUE;
  3044.     else if (c_ptr->cptr > 1) {
  3045.         m_list[c_ptr->cptr].csleep = 0;
  3046.     /* monptr of 0 is safe here, since can't reach here from creatures */
  3047.         return multiply_monster(y, x, (int)m_list[c_ptr->cptr].mptr, 0);
  3048.     }
  3049.     }
  3050.     while (!flag);
  3051.     return (FALSE);
  3052. }
  3053.  
  3054.  
  3055. /* Move the creature record to a new location        -RAK-     */
  3056. void 
  3057. teleport_away(monptr, dis)
  3058.     int                 monptr, dis;
  3059. {
  3060.     register int        yn, xn, ctr;
  3061.     register monster_type *m_ptr;
  3062.  
  3063.     m_ptr = &m_list[monptr];
  3064.     ctr = 0;
  3065.     do {
  3066.     do {
  3067.         yn = m_ptr->fy + (randint(2 * dis + 1) - (dis + 1));
  3068.         xn = m_ptr->fx + (randint(2 * dis + 1) - (dis + 1));
  3069.     }
  3070.     while (!in_bounds(yn, xn));
  3071.     ctr++;
  3072.     if (ctr > 9) {
  3073.         ctr = 0;
  3074.         dis += 5;
  3075.     }
  3076.     }
  3077.     while ((cave[yn][xn].fval >= MIN_CLOSED_SPACE) || (cave[yn][xn].cptr != 0));
  3078.     move_rec((int)m_ptr->fy, (int)m_ptr->fx, yn, xn);
  3079.     lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  3080.     m_ptr->fy = yn;
  3081.     m_ptr->fx = xn;
  3082. /*
  3083.  * this is necessary, because the creature is not currently visible in its
  3084.  * new position 
  3085.  */
  3086.     m_ptr->ml = FALSE;
  3087.     m_ptr->cdis = distance(char_row, char_col, yn, xn);
  3088.     update_mon(monptr);
  3089. }
  3090.  
  3091.  
  3092. /* Teleport player to spell casting creature        -RAK-     */
  3093. void 
  3094. teleport_to(ny, nx)
  3095.     int                 ny, nx;
  3096. {
  3097.     int                 dis, ctr, y, x, min_i, max_i, min_j, max_j;
  3098.     register int        i, j;
  3099.     register cave_type *c_ptr;
  3100.  
  3101.     dis = 1;
  3102.     ctr = 0;
  3103.     do {
  3104.     do {               /* bounds check added -CFT */
  3105.         y = ny + (randint(2 * dis + 1) - (dis + 1));
  3106.         x = nx + (randint(2 * dis + 1) - (dis + 1));
  3107.     } while (!in_bounds(y, x));
  3108.     ctr++;
  3109.     if (ctr > (4 * dis * dis + 4 * dis + 1)) {
  3110.         ctr = 0;
  3111.         dis++;
  3112.     }
  3113.     }
  3114.     while ((cave[y][x].fval >= MIN_CLOSED_SPACE) || (cave[y][x].cptr >= 2));
  3115.     move_rec(char_row, char_col, y, x);
  3116.  
  3117.     min_i = MY_MAX(0, (char_row - light_rad));
  3118.     max_i = MY_MIN(cur_height, (char_row + light_rad));
  3119.     min_j = MY_MAX(0, (char_col - light_rad));
  3120.     max_j = MY_MIN(cur_width, (char_col + light_rad));
  3121.  
  3122.     for (i = min_i; i <= max_i; i++)
  3123.     for (j = min_j; j <= max_j; j++) {
  3124.         c_ptr = &cave[i][j];
  3125.         c_ptr->tl = FALSE;
  3126.         lite_spot(i, j);
  3127.     }
  3128.     lite_spot(char_row, char_col);
  3129.     char_row = y;
  3130.     char_col = x;
  3131.     check_view();
  3132. /* light creatures */
  3133.     creatures(FALSE);
  3134. }
  3135.  
  3136.  
  3137. /* Teleport all creatures in a given direction away    -RAK-     */
  3138. int 
  3139. teleport_monster(dir, y, x)
  3140.     int                 dir, y, x;
  3141. {
  3142.     register int        flag, result, dist;
  3143.     register cave_type *c_ptr;
  3144.  
  3145.     flag = FALSE;
  3146.     result = FALSE;
  3147.     dist = 0;
  3148.     do {
  3149.     (void)mmove(dir, &y, &x);
  3150.     dist++;
  3151.     c_ptr = &cave[y][x];
  3152.     if ((dist > OBJ_BOLT_RANGE) || c_ptr->fval >= MIN_CLOSED_SPACE)
  3153.         flag = TRUE;
  3154.     else if (c_ptr->cptr > 1) {
  3155.         m_list[c_ptr->cptr].csleep = 0;    /* wake it up */
  3156.         teleport_away((int)c_ptr->cptr, MAX_SIGHT * 5);
  3157.         result = TRUE;
  3158.     }
  3159.     }
  3160.     while (!flag);
  3161.     return (result);
  3162. }
  3163.  
  3164.  
  3165. /* Delete all creatures within max_sight distance    -RAK-     */
  3166. /* NOTE : Winning creatures cannot be genocided             */
  3167. int 
  3168. mass_genocide(spell)
  3169.     int                 spell;
  3170. {
  3171.     register int        i, result;
  3172.     register monster_type *m_ptr;
  3173.     register creature_type *r_ptr;
  3174.  
  3175.     result = FALSE;
  3176.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3177.     m_ptr = &m_list[i];
  3178.     r_ptr = &c_list[m_ptr->mptr];
  3179.     if (((m_ptr->cdis <= MAX_SIGHT) && ((r_ptr->cmove & CM_WIN) == 0) &&
  3180.          ((r_ptr->cdefense & UNIQUE) == 0)) || (wizard &&
  3181.                           (m_ptr->cdis <= MAX_SIGHT))) {
  3182.         delete_monster(i);
  3183.         if (spell) {
  3184.         take_hit(randint(3), "the strain of casting Mass Genocide");
  3185.         prt_chp();
  3186.         put_qio();
  3187. #ifdef MSDOS
  3188.         delay(20* delay_spd);    /* milliseconds */
  3189. #else
  3190.         usleep(20000 * delay_spd);    /* useconds */
  3191. #endif
  3192.         }
  3193.         result = TRUE;
  3194.     }
  3195.     }
  3196.     return (result);
  3197. }
  3198.  
  3199. /* Delete all creatures of a given type from level.    -RAK-     */
  3200. /* This does not keep creatures of type from appearing later.     */
  3201. /* NOTE : Winning creatures can not be genocided. */
  3202. int 
  3203. genocide(spell)
  3204.     int                 spell;
  3205. {
  3206.     register int        i, killed;
  3207.     char                typ;
  3208.     register monster_type *m_ptr;
  3209.     register creature_type *r_ptr;
  3210.     vtype               out_val;
  3211.  
  3212.     killed = FALSE;
  3213.     if (get_com("Which type of creature do you wish exterminated?", &typ))
  3214.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3215.         m_ptr = &m_list[i];
  3216.         r_ptr = &c_list[m_ptr->mptr];
  3217.         if ((unsigned) typ == c_list[m_ptr->mptr].cchar)
  3218.         if ((r_ptr->cmove & CM_WIN) == 0) {
  3219.             delete_monster(i);
  3220.             if (spell) {
  3221.             take_hit(randint(4), "the strain of casting Genocide");
  3222.             prt_chp();
  3223.             put_qio();
  3224. #ifdef MSDOS
  3225.             delay(20 * delay_spd);    /* milliseconds */
  3226. #else
  3227.             usleep(20000 * delay_spd);    /* useconds */
  3228. #endif
  3229.             }
  3230.             killed = TRUE;
  3231.         } else {
  3232.         /*
  3233.          * genocide is a powerful spell, so we will let the player
  3234.          * know the names of the creatures he did not destroy, this
  3235.          * message makes no sense otherwise 
  3236.          */
  3237.             if (r_ptr->cdefense & UNIQUE)
  3238.             (void)sprintf(out_val, "%s is unaffected.", r_ptr->name);
  3239.             else
  3240.             (void)sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  3241.             msg_print(out_val);
  3242.         }
  3243.     }
  3244.     return (killed);
  3245. }
  3246.  
  3247.  
  3248. /* Change speed of any creature .            -RAK-     */
  3249. /* NOTE: cannot slow a winning creature (BALROG)         */
  3250. int 
  3251. speed_monsters(spd)
  3252.     int                 spd;
  3253. {
  3254.     register int        i, speed;
  3255.     register monster_type *m_ptr;
  3256.     register creature_type *r_ptr;
  3257.     vtype               out_val, m_name;
  3258.  
  3259.     speed = FALSE;
  3260.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3261.     m_ptr = &m_list[i];
  3262.     r_ptr = &c_list[m_ptr->mptr];
  3263.     monster_name(m_name, m_ptr, r_ptr);
  3264.  
  3265.     if (!los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx))
  3266.     /* do nothing */
  3267.         ;
  3268.     else if (spd > 0) {
  3269.         m_ptr->cspeed += spd;
  3270.         m_ptr->csleep = 0;
  3271.         if (m_ptr->ml) {
  3272.         speed = TRUE;
  3273.         (void)sprintf(out_val, "%s starts moving faster.", m_name);
  3274.         msg_print(out_val);
  3275.         }
  3276.     } else if ((r_ptr->level <
  3277.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) &&
  3278.            !(r_ptr->cdefense & UNIQUE)) {
  3279.         m_ptr->cspeed += spd;
  3280.         m_ptr->csleep = 0;
  3281.         if (m_ptr->ml) {
  3282.         (void)sprintf(out_val, "%s starts moving slower.", m_name);
  3283.         msg_print(out_val);
  3284.         speed = TRUE;
  3285.         }
  3286.     } else if (m_ptr->ml) {
  3287.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  3288.         msg_print(out_val);
  3289.     }
  3290.     }
  3291.     return (speed);
  3292. }
  3293.  
  3294.  
  3295. /* Sleep any creature .        -RAK-     */
  3296. int 
  3297. sleep_monsters2()
  3298. {
  3299.     register int        i, sleep;
  3300.     register monster_type *m_ptr;
  3301.     register creature_type *r_ptr;
  3302.     vtype               out_val, m_name;
  3303.  
  3304.     sleep = FALSE;
  3305.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3306.     m_ptr = &m_list[i];
  3307.     r_ptr = &c_list[m_ptr->mptr];
  3308.     monster_name(m_name, m_ptr, r_ptr);
  3309.     if ((m_ptr->cdis > MAX_SIGHT) ||
  3310.         !los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx))
  3311.     /* do nothing */
  3312.         ;
  3313.     else if ((r_ptr->level >
  3314.         randint((py.misc.lev - 10) < 1 ? 1 : (py.misc.lev - 10)) + 10) ||
  3315.         (r_ptr->cdefense & UNIQUE) || (r_ptr->cdefense & CHARM_SLEEP)) {
  3316.         if (m_ptr->ml) {
  3317.         if (r_ptr->cdefense & CHARM_SLEEP)
  3318.             c_recall[m_ptr->mptr].r_cdefense |= CHARM_SLEEP;
  3319.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  3320.         msg_print(out_val);
  3321.         }
  3322.     } else {
  3323.         m_ptr->csleep = 500;
  3324.         if (m_ptr->ml) {
  3325.         (void)sprintf(out_val, "%s falls asleep.", m_name);
  3326.         msg_print(out_val);
  3327.         sleep = TRUE;
  3328.         }
  3329.     }
  3330.     }
  3331.     return (sleep);
  3332. }
  3333.  
  3334. /* Polymorph any creature that player can see.    -RAK-     */
  3335. /* NOTE: cannot polymorph a unique creature             */
  3336. int 
  3337. mass_poly()
  3338. {
  3339.     register int        i;
  3340.     int                 y, x, mass;
  3341.     register monster_type *m_ptr;
  3342.     register creature_type *r_ptr;
  3343.     int                 l, j, k;
  3344.  
  3345.     mass = FALSE;
  3346.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3347.     m_ptr = &m_list[i];
  3348.     if (m_ptr->cdis <= MAX_SIGHT) {
  3349.         r_ptr = &c_list[m_ptr->mptr];
  3350.         if (((r_ptr->cmove & CM_WIN) == 0) && !(r_ptr->cdefense & UNIQUE)) {
  3351.         y = m_ptr->fy;
  3352.         x = m_ptr->fx;
  3353.         l = (randint(20) / randint(9)) + 1;
  3354.         j = r_ptr->level - l;    /* get range of levels... */
  3355.         k = r_ptr->level + l;
  3356.         if (j < 0)
  3357.             j = 0;
  3358.         if (k > MAX_MONS_LEVEL)
  3359.             k = MAX_MONS_LEVEL;
  3360.         delete_monster(cave[y][x].cptr);
  3361.         do {
  3362.             l = randint(m_level[k] - m_level[j]) - 1 + m_level[j];
  3363.         /* monster index */
  3364.             if ((c_list[l].cdefense & UNIQUE) == 0)
  3365.             place_monster(y, x, l, FALSE);
  3366.         } while (cave[y][x].cptr < MIN_MONIX);
  3367.         mass = TRUE;
  3368.         }
  3369.     }
  3370.     }
  3371.     return (mass);
  3372. }
  3373.  
  3374. int 
  3375. chaos(m_ptr2)
  3376.     monster_type       *m_ptr2;
  3377. {
  3378.     register int        i;
  3379.     int                 y, x, mass;
  3380.     register monster_type *m_ptr;
  3381.     register creature_type *r_ptr;
  3382.  
  3383.     mass = FALSE;
  3384.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3385.     m_ptr = &m_list[i];
  3386.     if (m_ptr->cdis < MAX_SIGHT) {
  3387.         r_ptr = &c_list[m_ptr->mptr];
  3388.         if (!(r_ptr->cdefense & UNIQUE) && m_ptr != m_ptr2) {
  3389.         y = m_ptr->fy;
  3390.         x = m_ptr->fx;
  3391.         delete_monster(i);
  3392.         place_monster(y, x, randint(m_level[MAX_MONS_LEVEL] - m_level[0])
  3393.                   - 1 + m_level[0], FALSE);
  3394.         mass = TRUE;
  3395.         }
  3396.     }
  3397.     }
  3398.     return (mass);
  3399. }
  3400.  
  3401. /* Display evil creatures on current panel        -RAK-     */
  3402. int 
  3403. detect_evil()
  3404. {
  3405.     register int        i, flag;
  3406.     register monster_type *m_ptr;
  3407.  
  3408.     flag = FALSE;
  3409.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3410.     m_ptr = &m_list[i];
  3411.     if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx) &&
  3412.         (EVIL & c_list[m_ptr->mptr].cdefense)) {
  3413.         m_ptr->ml = TRUE;
  3414.     /* works correctly even if hallucinating */
  3415.         print((char)c_list[m_ptr->mptr].cchar, (int)m_ptr->fy,
  3416.           (int)m_ptr->fx);
  3417.         flag = TRUE;
  3418.     }
  3419.     }
  3420.     if (flag) {
  3421.     msg_print("You sense the presence of evil!");
  3422.     msg_print(NULL);
  3423.     /* must unlight every monster just lighted */
  3424.     creatures(FALSE);
  3425.     }
  3426.     return (flag);
  3427. }
  3428.  
  3429.  
  3430. /* Change players hit points in some manner        -RAK-     */
  3431. int 
  3432. hp_player(num)
  3433.     int                 num;
  3434. {
  3435.     register int        res;
  3436.     register struct misc *m_ptr;
  3437.  
  3438.     res = FALSE;
  3439.     m_ptr = &py.misc;
  3440.     if (m_ptr->chp < m_ptr->mhp) {
  3441.     m_ptr->chp += num;
  3442.     if (m_ptr->chp > m_ptr->mhp) {
  3443.         m_ptr->chp = m_ptr->mhp;
  3444.         m_ptr->chp_frac = 0;
  3445.     }
  3446.     prt_chp();
  3447.  
  3448.     num = num / 5;
  3449.     if (num < 3) {
  3450.         if (num == 0)
  3451.         msg_print("You feel a little better.");
  3452.         else
  3453.         msg_print("You feel better.");
  3454.     } else {
  3455.         if (num < 7)
  3456.         msg_print("You feel much better.");
  3457.         else
  3458.         msg_print("You feel very good.");
  3459.     }
  3460.     res = TRUE;
  3461.     }
  3462.     return (res);
  3463. }
  3464.  
  3465.  
  3466. /* Cure players confusion                -RAK-     */
  3467. int 
  3468. cure_confusion()
  3469. {
  3470.     register int        cure;
  3471.     register struct flags *f_ptr;
  3472.  
  3473.     cure = FALSE;
  3474.     f_ptr = &py.flags;
  3475.     if (f_ptr->confused > 1) {
  3476.     f_ptr->confused = 1;
  3477.     cure = TRUE;
  3478.     }
  3479.     return (cure);
  3480. }
  3481.  
  3482.  
  3483. /* Cure players blindness                -RAK-     */
  3484. int 
  3485. cure_blindness()
  3486. {
  3487.     register int        cure;
  3488.     register struct flags *f_ptr;
  3489.  
  3490.     cure = FALSE;
  3491.     f_ptr = &py.flags;
  3492.     if (f_ptr->blind > 1) {
  3493.     f_ptr->blind = 1;
  3494.     cure = TRUE;
  3495.     }
  3496.     return (cure);
  3497. }
  3498.  
  3499.  
  3500. /* Cure poisoning                    -RAK-     */
  3501. int 
  3502. cure_poison()
  3503. {
  3504.     register int        cure;
  3505.     register struct flags *f_ptr;
  3506.  
  3507.     cure = FALSE;
  3508.     f_ptr = &py.flags;
  3509.     if (f_ptr->poisoned > 1) {
  3510.     f_ptr->poisoned = 1;
  3511.     cure = TRUE;
  3512.     }
  3513.     return (cure);
  3514. }
  3515.  
  3516.  
  3517. /* Cure the players fear                -RAK-     */
  3518. int 
  3519. remove_fear()
  3520. {
  3521.     register int        result;
  3522.     register struct flags *f_ptr;
  3523.  
  3524.     result = FALSE;
  3525.     f_ptr = &py.flags;
  3526.     if (f_ptr->afraid > 1) {
  3527.     f_ptr->afraid = 1;
  3528.     result = TRUE;
  3529.     }
  3530.     return (result);
  3531. }
  3532.  
  3533.  
  3534. /* This is a fun one.  In a given block, pick some walls and     */
  3535. /* turn them into open spots.  Pick some open spots and turn     */
  3536. /* them into walls.  An "Earthquake" effect.           -RAK-   */
  3537. void 
  3538. earthquake()
  3539. {
  3540.     register int        i, j;
  3541.     register cave_type *c_ptr;
  3542.     register monster_type *m_ptr;
  3543.     register creature_type *r_ptr;
  3544.     int                 kill, damage, tmp, y, x;
  3545.     vtype               out_val, m_name;
  3546.  
  3547.     for (i = char_row - 8; i <= char_row + 8; i++)
  3548.     for (j = char_col - 8; j <= char_col + 8; j++)
  3549.         if (((i != char_row) || (j != char_col)) &&
  3550.         in_bounds(i, j) && (randint(8) == 1)) {
  3551.         c_ptr = &cave[i][j];
  3552.         if (c_ptr->tptr != 0)
  3553.             if (((t_list[c_ptr->tptr].tval >= TV_MIN_WEAR) &&
  3554.              (t_list[c_ptr->tptr].tval <= TV_MAX_WEAR) &&
  3555.              (t_list[c_ptr->tptr].flags2 & TR_ARTIFACT))
  3556.             || (t_list[c_ptr->tptr].tval == TV_UP_STAIR)
  3557.             || (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR)
  3558.             || (t_list[c_ptr->tptr].tval == TV_STORE_DOOR))
  3559.             continue;  /* don't touch artifacts or stairs or
  3560.                     * stores -CFT */
  3561.             else
  3562.             (void)delete_object(i, j);
  3563.         if (c_ptr->cptr > 1) {
  3564.             m_ptr = &m_list[c_ptr->cptr];
  3565.             r_ptr = &c_list[m_ptr->mptr];
  3566.  
  3567.             if (!(r_ptr->cmove & CM_PHASE) && !(r_ptr->cdefense & BREAK_WALL)) {
  3568.             if ((movement_rate(m_ptr->cspeed) == 0) ||
  3569.                 (r_ptr->cmove & CM_ATTACK_ONLY))
  3570.             /* monster can not move to escape the wall */
  3571.                 kill = TRUE;
  3572.             else {
  3573.             /*
  3574.              * only kill if there is nowhere for the monster to
  3575.              * escape to 
  3576.              */
  3577.                 kill = TRUE;
  3578.                 for (y = i - 1; y <= i + 1; y++)
  3579.                 for (x = j - 1; x <= j + 1; x++)
  3580.                     if (cave[y][x].fval >= MIN_CLOSED_SPACE)
  3581.                     kill = FALSE;
  3582.             }
  3583.             if (kill)
  3584.                 damage = 320;
  3585.             else
  3586.                 damage = damroll(4, 8);
  3587.             monster_name(m_name, m_ptr, r_ptr);
  3588.             (void)sprintf(out_val, "%s wails out in pain!", m_name);
  3589.             msg_print(out_val);
  3590.             i = mon_take_hit((int)c_ptr->cptr, damage, TRUE);
  3591.             if (i >= 0) {
  3592.                 (void)sprintf(out_val, "%s is embedded in the rock.",
  3593.                       m_name);
  3594.                 msg_print(out_val);
  3595.             /* prt_experience(); */
  3596.             }
  3597.             }
  3598.         }
  3599.         if ((c_ptr->fval >= MIN_CAVE_WALL) && (c_ptr->fval != BOUNDARY_WALL)) {
  3600.             c_ptr->fval = CORR_FLOOR;
  3601.             c_ptr->pl = FALSE;
  3602.             c_ptr->fm = FALSE;
  3603.         } else if (c_ptr->fval <= MAX_CAVE_FLOOR) {
  3604.             tmp = randint(10);
  3605.             if (tmp < 6)
  3606.             c_ptr->fval = QUARTZ_WALL;
  3607.             else if (tmp < 9)
  3608.             c_ptr->fval = MAGMA_WALL;
  3609.             else
  3610.             c_ptr->fval = GRANITE_WALL;
  3611.  
  3612.             c_ptr->fm = FALSE;
  3613.         }
  3614.         lite_spot(i, j);
  3615.         }
  3616. }
  3617.  
  3618.  
  3619. /* Evil creatures don't like this.               -RAK-   */
  3620. int 
  3621. protect_evil()
  3622. {
  3623.     register int        res;
  3624.     register struct flags *f_ptr;
  3625.  
  3626.     f_ptr = &py.flags;
  3627.     if (f_ptr->protevil == 0)
  3628.     res = TRUE;
  3629.     else
  3630.     res = FALSE;
  3631.     f_ptr->protevil += randint(25) + 3 * py.misc.lev;
  3632.     return (res);
  3633. }
  3634.  
  3635.  
  3636. /* Create some high quality mush for the player.    -RAK-     */
  3637. void 
  3638. create_food()
  3639. {
  3640. #if 0
  3641.     register cave_type *c_ptr;
  3642.  
  3643.     c_ptr = &cave[char_row][char_col];
  3644.     if (c_ptr->tptr != 0) {
  3645.     /* take no action here, don't want to destroy object under player */
  3646.     msg_print("There is already an object under you.");
  3647.     /* set free_turn_flag so that scroll/spell points won't be used */
  3648.     free_turn_flag = TRUE;
  3649.     } else {
  3650.     int                 cur_pos, tmp;
  3651.  
  3652.     cur_pos = popt();
  3653.     cave[char_row][char_col].tptr = cur_pos;
  3654.     tmp = get_obj_num(dun_level, FALSE);
  3655.     invcopy(&t_list[cur_pos], OBJ_MUSH);
  3656.     msg_print("You feel something roll beneath your feet.");
  3657.     }
  3658. #endif
  3659.  
  3660.      /* add to food timer rather than create mush - cba */
  3661.      add_food(object_list[OBJ_MUSH].p1);
  3662.      py.flags.status &= ~(PY_WEAK | PY_HUNGRY);
  3663.      prt_hunger();
  3664. }
  3665.  
  3666. int 
  3667. banish_creature(cflag, dist)
  3668.     int32u              cflag;
  3669.     int                 dist;
  3670. {
  3671.     register int        i;
  3672.     int                 dispel;
  3673.     register monster_type *m_ptr;
  3674.  
  3675.     dispel = FALSE;
  3676.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3677.     m_ptr = &m_list[i];
  3678.     if ((cflag & c_list[m_ptr->mptr].cdefense) &&
  3679.         (m_ptr->cdis <= MAX_SIGHT) &&
  3680.         los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx)) {
  3681.         c_recall[m_ptr->mptr].r_cdefense |= cflag;
  3682.         (void)teleport_away(i, dist);
  3683.         dispel = TRUE;
  3684.     }
  3685.     }
  3686.     return (dispel);
  3687. }
  3688.  
  3689. int 
  3690. probing()
  3691. {
  3692.     register int        i;
  3693.     int                 probe;
  3694.     register monster_type *m_ptr;
  3695.     register creature_type *r_ptr;
  3696.     vtype               out_val, m_name;
  3697.  
  3698.     msg_print("Probing...");
  3699.     probe = FALSE;
  3700.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3701.     m_ptr = &m_list[i];
  3702.     r_ptr = &c_list[m_ptr->mptr];
  3703.     if ((m_ptr->cdis <= MAX_SIGHT) &&
  3704.         los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx)) {
  3705.         if (!m_ptr->ml) {
  3706.         break;
  3707.         } else {
  3708.         if (r_ptr->cdefense & UNIQUE)
  3709.             sprintf(m_name, "%s", r_ptr->name);
  3710.         else
  3711.             sprintf(m_name, "The %s", r_ptr->name);
  3712.         }
  3713.         sprintf(out_val, "%s has %d hit points.", m_name, m_ptr->hp);
  3714.         move_cursor_relative(m_ptr->fy, m_ptr->fx);
  3715.         msg_print(out_val);
  3716.         probe = TRUE;
  3717.     }
  3718.     }
  3719.     if (probe)
  3720.     msg_print("That's all.");
  3721.     else
  3722.     msg_print("You find nothing to probe.");
  3723.     move_cursor_relative(char_row, char_col);
  3724.     return (probe);
  3725. }
  3726.  
  3727. /* Attempts to destroy a type of creature.  Success depends on     */
  3728. /* the creatures level VS. the player's level         -RAK-     */
  3729. int 
  3730. dispel_creature(cflag, damage)
  3731.     int                 cflag;
  3732.     int                 damage;
  3733. {
  3734.     register int        i;
  3735.     int                 k, dispel, visible;
  3736.     register monster_type *m_ptr;
  3737.     register creature_type *r_ptr;
  3738.     vtype               out_val, m_name;
  3739.  
  3740.     dispel = FALSE;
  3741.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3742.     m_ptr = &m_list[i];
  3743.     if ((cflag & c_list[m_ptr->mptr].cdefense) &&
  3744.         (m_ptr->cdis <= MAX_SIGHT) &&
  3745.         los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx)) {
  3746.         r_ptr = &c_list[m_ptr->mptr];
  3747.         c_recall[m_ptr->mptr].r_cdefense |= cflag;
  3748.         visible = m_ptr->ml;   /* set this before call mon_take_hit */
  3749.         k = mon_take_hit(i, randint(damage), FALSE);
  3750.         if (visible)
  3751.         monster_name(m_name, m_ptr, r_ptr);
  3752.         else
  3753.         strcpy(m_name, "It");
  3754.         if (k >= 0)
  3755.         (void)sprintf(out_val, "%s dissolves!", m_name);
  3756.         else
  3757.         (void)sprintf(out_val, "%s shudders.", m_name);
  3758.         msg_print(out_val);
  3759.         dispel = TRUE;
  3760.         if (k >= 0)
  3761.         prt_experience();
  3762.     }
  3763.     }
  3764.     return (dispel);
  3765. }
  3766.  
  3767.  
  3768. /* Attempt to turn (confuse) undead creatures.    -RAK-     */
  3769. int 
  3770. turn_undead()
  3771. {
  3772.     register int        i, turn_und;
  3773.     register monster_type *m_ptr;
  3774.     register creature_type *r_ptr;
  3775.     vtype               out_val, m_name;
  3776.  
  3777.     turn_und = FALSE;
  3778.     for (i = mfptr - 1; i >= MIN_MONIX; i--) {
  3779.     m_ptr = &m_list[i];
  3780.     r_ptr = &c_list[m_ptr->mptr];
  3781.     if ((UNDEAD & r_ptr->cdefense)
  3782.         && (m_ptr->cdis <= MAX_SIGHT)
  3783.         && (los(char_row, char_col, (int)m_ptr->fy, (int)m_ptr->fx))) {
  3784.         monster_name(m_name, m_ptr, r_ptr);
  3785.         if (((py.misc.lev + 1) > r_ptr->level) ||
  3786.         (randint(5) == 1)) {
  3787.         if (m_ptr->ml) {
  3788.             (void)sprintf(out_val, "%s runs frantically!", m_name);
  3789.             msg_print(out_val);
  3790.             turn_und = TRUE;
  3791.             c_recall[m_ptr->mptr].r_cdefense |= UNDEAD;
  3792.         }
  3793.         m_ptr->monfear = randint(py.misc.lev) * 2;
  3794.         } else if (m_ptr->ml) {
  3795.         (void)sprintf(out_val, "%s is unaffected.", m_name);
  3796.         msg_print(out_val);
  3797.         }
  3798.     }
  3799.     }
  3800.     return (turn_und);
  3801. }
  3802.  
  3803.  
  3804. /* Leave a glyph of warding. Creatures will not pass over! -RAK- */
  3805. void 
  3806. warding_glyph()
  3807. {
  3808.     register int        i;
  3809.     register cave_type *c_ptr;
  3810.  
  3811.     c_ptr = &cave[char_row][char_col];
  3812.     if (c_ptr->tptr == 0) {
  3813.     i = popt();
  3814.     c_ptr->tptr = i;
  3815.     invcopy(&t_list[i], OBJ_SCARE_MON);
  3816.     }
  3817. }
  3818.  
  3819.  
  3820. /* Lose a strength point.                -RAK-     */
  3821. void 
  3822. lose_str()
  3823. {
  3824.     if (!py.flags.sustain_str) {
  3825.     (void)dec_stat(A_STR);
  3826.     msg_print("You feel very weak.");
  3827.     } else
  3828.     msg_print("You feel weak for a moment;  it passes.");
  3829. }
  3830.  
  3831.  
  3832. /* Lose an intelligence point.                -RAK-     */
  3833. void 
  3834. lose_int()
  3835. {
  3836.     if (!py.flags.sustain_int) {
  3837.     (void)dec_stat(A_INT);
  3838.     msg_print("You become very dizzy.");
  3839.     } else
  3840.     msg_print("You become dizzy for a moment;  it passes.");
  3841. }
  3842.  
  3843.  
  3844. /* Lose a wisdom point.                    -RAK-     */
  3845. void 
  3846. lose_wis()
  3847. {
  3848.     if (!py.flags.sustain_wis) {
  3849.     (void)dec_stat(A_WIS);
  3850.     msg_print("You feel very naive.");
  3851.     } else
  3852.     msg_print("You feel naive for a moment;  it passes.");
  3853. }
  3854.  
  3855.  
  3856. /* Lose a dexterity point.                -RAK-     */
  3857. void 
  3858. lose_dex()
  3859. {
  3860.     if (!py.flags.sustain_dex) {
  3861.     (void)dec_stat(A_DEX);
  3862.     msg_print("You feel very sore.");
  3863.     } else
  3864.     msg_print("You feel sore for a moment;  it passes.");
  3865. }
  3866.  
  3867.  
  3868. /* Lose a constitution point.                -RAK-     */
  3869. void 
  3870. lose_con()
  3871. {
  3872.     if (!py.flags.sustain_con) {
  3873.     (void)dec_stat(A_CON);
  3874.     msg_print("You feel very sick.");
  3875.     } else
  3876.     msg_print("You feel sick for a moment;  it passes.");
  3877. }
  3878.  
  3879.  
  3880. /* Lose a charisma point.                -RAK-     */
  3881. void 
  3882. lose_chr()
  3883. {
  3884.     if (!py.flags.sustain_chr) {
  3885.     (void)dec_stat(A_CHR);
  3886.     msg_print("Your skin starts to itch.");
  3887.     } else
  3888.     msg_print("Your skin starts to itch, but feels better now.");
  3889. }
  3890.  
  3891.  
  3892. /* Lose experience                    -RAK-     */
  3893. void 
  3894. lose_exp(amount)
  3895.     int32               amount;
  3896. {
  3897.     register int        i;
  3898.     register struct misc *m_ptr;
  3899.     register class_type *c_ptr;
  3900.  
  3901.     m_ptr = &py.misc;
  3902.     if (amount > m_ptr->exp)
  3903.     m_ptr->exp = 0;
  3904.     else
  3905.     m_ptr->exp -= amount;
  3906.     prt_experience();
  3907.  
  3908.     i = 0;
  3909.     while (((player_exp[i] * m_ptr->expfact / 100) <= m_ptr->exp)
  3910.        && (i < MAX_PLAYER_LEVEL))
  3911.     i++;
  3912. /* increment i once more, because level 1 exp is stored in player_exp[0] */
  3913.     i++;
  3914.     if (i > MAX_PLAYER_LEVEL)
  3915.     i = MAX_PLAYER_LEVEL;
  3916.     if (m_ptr->lev != i) {
  3917.     m_ptr->lev = i;
  3918.  
  3919.     calc_hitpoints();
  3920.     c_ptr = &class[m_ptr->pclass];
  3921.     if (c_ptr->spell == MAGE) {
  3922.         calc_spells(A_INT);
  3923.         calc_mana(A_INT);
  3924.     } else if (c_ptr->spell == PRIEST) {
  3925.         calc_spells(A_WIS);
  3926.         calc_mana(A_WIS);
  3927.     }
  3928.     prt_level();
  3929.     prt_title();
  3930.     }
  3931. }
  3932.  
  3933.  
  3934. /* Slow Poison                        -RAK-     */
  3935. int 
  3936. slow_poison()
  3937. {
  3938.     register int        slow;
  3939.     register struct flags *f_ptr;
  3940.  
  3941.     slow = FALSE;
  3942.     f_ptr = &py.flags;
  3943.     if (f_ptr->poisoned > 0) {
  3944.     f_ptr->poisoned = f_ptr->poisoned / 2;
  3945.     if (f_ptr->poisoned < 1)
  3946.         f_ptr->poisoned = 1;
  3947.     slow = TRUE;
  3948.     msg_print("The effect of the poison has been reduced.");
  3949.     }
  3950.     return (slow);
  3951. }
  3952.  
  3953.  
  3954. /* Bless                        -RAK-     */
  3955. void 
  3956. bless(amount)
  3957.     int                 amount;
  3958. {
  3959.     py.flags.blessed += amount;
  3960. }
  3961.  
  3962.  
  3963. /* Detect Invisible for period of time            -RAK-     */
  3964. void 
  3965. detect_inv2(amount)
  3966.     int                 amount;
  3967. {
  3968.     py.flags.detect_inv += amount;
  3969. }
  3970.  
  3971.  
  3972. static void 
  3973. replace_spot(y, x, typ)
  3974.     int                 y, x, typ;
  3975. {
  3976.     register cave_type *c_ptr;
  3977.  
  3978.     c_ptr = &cave[y][x];
  3979.     switch (typ) {
  3980.       case 1:
  3981.       case 2:
  3982.       case 3:
  3983.     c_ptr->fval = CORR_FLOOR;
  3984.     break;
  3985.       case 4:
  3986.       case 7:
  3987.       case 10:
  3988.     c_ptr->fval = GRANITE_WALL;
  3989.     break;
  3990.       case 5:
  3991.       case 8:
  3992.       case 11:
  3993.     c_ptr->fval = MAGMA_WALL;
  3994.     break;
  3995.       case 6:
  3996.       case 9:
  3997.       case 12:
  3998.     c_ptr->fval = QUARTZ_WALL;
  3999.     break;
  4000.     }
  4001.     c_ptr->pl = FALSE;
  4002.     c_ptr->fm = FALSE;
  4003.     c_ptr->lr = FALSE;           /* this is no longer part of a room */
  4004.     if (c_ptr->tptr != 0)
  4005.     (void)delete_object(y, x);
  4006.     if (c_ptr->cptr > 1)
  4007.     delete_monster((int)c_ptr->cptr);
  4008. }
  4009.  
  4010.  
  4011. /* The spell of destruction.                -RAK-     */
  4012. /* NOTE : Winning creatures that are deleted will be considered     */
  4013. /* as teleporting to another level.  This will NOT win the */
  4014. /* game.                               */
  4015. void 
  4016. destroy_area(y, x)
  4017.     register int        y, x;
  4018. {
  4019.     register int        i, j, k;
  4020.  
  4021.     msg_print("There is a searing blast of light!");
  4022.     if (!py.flags.blindness_resist && !py.flags.light_resist)
  4023.     py.flags.blind += 10 + randint(10);
  4024.     if (dun_level > 0) {
  4025.     for (i = (y - 15); i <= (y + 15); i++)
  4026.         for (j = (x - 15); j <= (x + 15); j++)
  4027.         if (in_bounds(i, j) && (cave[i][j].fval != BOUNDARY_WALL) &&
  4028.             ((cave[i][j].tptr == 0) ||
  4029.              ((t_list[cave[i][j].tptr].tval != TV_UP_STAIR) &&
  4030.               (t_list[cave[i][j].tptr].tval != TV_DOWN_STAIR) &&
  4031.               (!(t_list[cave[i][j].tptr].flags2 & TR_ARTIFACT))))) {    /* DGK */
  4032.             k = distance(i, j, y, x);
  4033.             if (k == 0)       /* player's spot... */
  4034.             replace_spot(i, j, 1);    /* clear player's spot...
  4035.                          * from um55 -CFT */
  4036.             else if (k < 13)
  4037.             replace_spot(i, j, randint(6));
  4038.             else if (k < 16)
  4039.             replace_spot(i, j, randint(9));
  4040.         }
  4041.     }
  4042.     if (py.flags.blindness_resist || py.flags.light_resist) {    /* We need to redraw the
  4043.                                  * screen. -DGK */
  4044.     draw_cave();
  4045.     creatures(FALSE);       /* draw monsters */
  4046.     }
  4047. }
  4048.  
  4049.  
  4050. /* Enchants a plus onto an item.                        -RAK-   */
  4051. int 
  4052. enchant(plusses, my_limit)
  4053.     int16              *plusses;
  4054.     int                 my_limit;  /* maximum bonus allowed; usually 10, but
  4055.                     * weapon's maximum damage when enchanting
  4056.                     * melee weapons to damage */
  4057.  
  4058. /* *Enchant Weapon/Armor* increases limit by 5 -DGK */
  4059. {
  4060.     int16               limit = (int16) my_limit;
  4061.     register int        chance, res;
  4062.  
  4063.     if (limit <= 0)           /* avoid randint(0) call */
  4064.     return (FALSE);
  4065.     if (limit > 25)           /* Glaives of Pain (+10, +60) are -BAD-!
  4066.                     * -DGK */
  4067.     limit = 25;
  4068.     chance = 0;
  4069.     res = FALSE;
  4070.     if (*plusses > 0) {
  4071.     chance = *plusses;
  4072.     if (randint(100) == 1)       /* very rarely allow enchantment over
  4073.                     * limit */
  4074.         chance = randint(chance) - 1;
  4075.     }
  4076.     if (randint(limit) > chance) {
  4077.     *plusses += 1;
  4078.     res = TRUE;
  4079.     }
  4080.     return (res);
  4081. }
  4082.  
  4083.  
  4084. void 
  4085. elemental_brand()
  4086. {
  4087.     register inven_type *i_ptr;
  4088.  
  4089.     i_ptr = &inventory[INVEN_WIELD];
  4090.     if (i_ptr->tval != TV_NOTHING && i_ptr->name2 == SN_NULL &&
  4091.     i_ptr->tval != TV_BOW) {
  4092.     int                 k, l, hot = randint(2) - 1;
  4093.     char                tmp_str[100], out_val[100];
  4094.  
  4095.     objdes(tmp_str, i_ptr, FALSE);
  4096.     if (hot) {
  4097.         if (i_ptr->number == 1)
  4098.         sprintf(out_val, "Your %s glows with a fiery aura!", tmp_str);
  4099.         else
  4100.         sprintf(out_val, "Your %s glow with a fiery aura!", tmp_str);
  4101.         if (inventory[INVEN_WIELD].tval != TV_NOTHING) {
  4102.         i_ptr->name2 = SN_FT;
  4103.         i_ptr->flags |= (TR_FLAME_TONGUE | TR_RES_FIRE);
  4104.         } else {
  4105.         i_ptr->name2 = SN_FIRE;
  4106.         i_ptr->flags |= TR_FLAME_TONGUE;
  4107.         }
  4108.     } else {
  4109.         if (i_ptr->number == 1)
  4110.         sprintf(out_val, "Your %s glows a deep, icy blue!", tmp_str);
  4111.         else
  4112.         sprintf(out_val, "Your %s glow a deep, icy blue!", tmp_str);
  4113.         i_ptr->name2 = SN_FB;
  4114.         if (inventory[INVEN_WIELD].tval != TV_NOTHING)
  4115.         i_ptr->flags |= (TR_FROST_BRAND | TR_RES_COLD);
  4116.         else
  4117.         i_ptr->flags |= (TR_FROST_BRAND);
  4118.     }
  4119.     msg_print(out_val);
  4120.  
  4121.     k = 3 + randint(3);
  4122.     for (l = 0; l < k; l++)       /* Don't need to check if it's an artifact */
  4123.         enchant(&i_ptr->tohit, 10);    /* since ->name2 is checked -DGK */
  4124.     k = 3 + randint(3);
  4125.     for (l = 0; l < k; l++)
  4126.         enchant(&i_ptr->todam, ((i_ptr->damage[0]) * (i_ptr->damage[1])));
  4127.     /* used to clear TR_CURSED; should remain set -DGK- */
  4128.     calc_bonuses();
  4129.     } else
  4130.     msg_print("The Branding fails.");
  4131. }
  4132.  
  4133.  
  4134.  
  4135. const char               *
  4136. pain_message(monptr, dam)
  4137.     int                 monptr, dam;
  4138. {
  4139.     register monster_type *m_ptr;
  4140.     creature_type      *c_ptr;
  4141.     int                 percentage, oldhp, newhp;
  4142.  
  4143.     if (dam == 0)
  4144.     return "%s is unharmed.";  /* avoid potential div by 0 */
  4145.  
  4146.     m_ptr = &m_list[monptr];
  4147.     c_ptr = &c_list[m_ptr->mptr];
  4148. #ifdef MSDOS               /* more fix -CFT */
  4149.     newhp = (int32) (m_ptr->hp);
  4150.     oldhp = newhp + (int32) dam;
  4151. #else
  4152.     newhp = m_ptr->hp;
  4153.     oldhp = newhp + dam;
  4154. #endif
  4155.     percentage = (newhp * 100) / oldhp;
  4156.  
  4157.     if ((c_ptr->cchar == 'j') ||   /* Non-verbal creatures like molds */
  4158.     (c_ptr->cchar == 'Q') || (c_ptr->cchar == 'v') ||
  4159.      (c_ptr->cchar == 'm') || ((c_ptr->cchar == 'e') && stricmp(c_ptr->name,
  4160.                                  "Beholder"))) {
  4161.     if (percentage > 95)
  4162.         return "%s barely notices.";
  4163.     if (percentage > 75)
  4164.         return "%s flinches.";
  4165.     if (percentage > 50)
  4166.         return "%s squelches.";
  4167.     if (percentage > 35) {
  4168.         if (randint(4) == 1) /* thanks to dbd@panacea.phys.utk.edu -CWS */
  4169.         return "%s quivers in pain.";
  4170.         else
  4171.         return "%s imitates Bill Cosby in pain.";
  4172.     }
  4173.     if (percentage > 20)
  4174.         return "%s writhes about.";
  4175.     if (percentage > 10)
  4176.         return "%s writhes in agony.";
  4177.     return "%s jerks limply.";
  4178.     } else if (c_ptr->cchar == 'C' || c_ptr->cchar == 'Z') {
  4179.     if (percentage > 95)
  4180.         return "%s shrugs off the attack.";
  4181.     if (percentage > 75)
  4182.         return "%s snarls with pain.";
  4183.     if (percentage > 50)
  4184.         return "%s yelps in pain.";
  4185.     if (percentage > 35)
  4186.         return "%s howls in pain.";
  4187.     if (percentage > 20)
  4188.         return "%s howls in agony.";
  4189.     if (percentage > 10)
  4190.         return "%s writhes in agony.";
  4191.     return "%s yelps feebly.";
  4192.     } else if (c_ptr->cchar == 'K' || c_ptr->cchar == 'c' || c_ptr->cchar == 'a' ||
  4193.     c_ptr->cchar == 'U' || c_ptr->cchar == 'q' || c_ptr->cchar == 'R' ||
  4194.     c_ptr->cchar == 'X' || c_ptr->cchar == 'b' || c_ptr->cchar == 'F' ||
  4195.     c_ptr->cchar == 'J' || c_ptr->cchar == 'l' || c_ptr->cchar == 'r' ||
  4196.     c_ptr->cchar == 's' || c_ptr->cchar == 'S' || c_ptr->cchar == 't') {
  4197.     if (percentage > 95)
  4198.         return "%s ignores the attack.";
  4199.     if (percentage > 75)
  4200.         return "%s grunts with pain.";
  4201.     if (percentage > 50)
  4202.         return "%s squeals in pain.";
  4203.     if (percentage > 35)
  4204.         return "%s shrieks in pain.";
  4205.     if (percentage > 20)
  4206.         return "%s shrieks in agony.";
  4207.     if (percentage > 10)
  4208.         return "%s writhes in agony.";
  4209.     return "%s cries out feebly.";
  4210.     } else {
  4211.     if (percentage > 95)
  4212.         return "%s shrugs off the attack.";
  4213.     if (percentage > 75)
  4214.         return "%s grunts with pain.";
  4215.     if (percentage > 50)
  4216.         return "%s cries out in pain.";
  4217.     if (percentage > 35)
  4218.         return "%s screams in pain.";
  4219.     if (percentage > 20)
  4220.         return "%s screams in agony.";
  4221.     if (percentage > 10)
  4222.         return "%s writhes in agony.";
  4223.     return "%s cries out feebly.";
  4224.     }
  4225. }
  4226.  
  4227. /* Removes curses from items in inventory        -RAK-     */
  4228. int 
  4229. remove_curse()
  4230. {
  4231.     register int        i, result;
  4232.     register inven_type *i_ptr;
  4233.  
  4234.     result = FALSE;
  4235.     for (i = INVEN_WIELD; i <= INVEN_OUTER; i++) {
  4236.     i_ptr = &inventory[i];
  4237.     if ((TR_CURSED & i_ptr->flags) &&
  4238.         (i_ptr->name2 != SN_MORGUL) &&
  4239.         (i_ptr->name2 != SN_CALRIS) &&
  4240.         (i_ptr->name2 != SN_MORMEGIL)) {
  4241.         if (!(!stricmp(object_list[i_ptr->index].name, "Power") &&
  4242.           (i_ptr->tval == TV_RING))) {
  4243.         i_ptr->flags &= ~TR_CURSED;
  4244.         i_ptr->ident &= ~ID_DAMD;    /* DGK */
  4245.         i_ptr->inscrip[0] = '\0';
  4246.         calc_bonuses();
  4247.         result = TRUE;
  4248.         }
  4249.     }
  4250.     }
  4251.     return (result);
  4252. }
  4253.  
  4254. int 
  4255. remove_all_curse()
  4256. {
  4257.     register int        i, result;
  4258.     register inven_type *i_ptr;
  4259.  
  4260.     result = FALSE;
  4261.     for (i = INVEN_WIELD; i <= INVEN_OUTER; i++) {
  4262.     i_ptr = &inventory[i];
  4263.     if (TR_CURSED & i_ptr->flags) {
  4264.         if (!(!stricmp(object_list[i_ptr->index].name, "Power") &&
  4265.           (i_ptr->tval == TV_RING))) {
  4266.         i_ptr->flags &= ~TR_CURSED;
  4267.         i_ptr->ident &= ~ID_DAMD;    /* DGK */
  4268.         calc_bonuses();
  4269.         i_ptr->inscrip[0] = '\0';
  4270.         result = TRUE;
  4271.         } else {
  4272.         msg_print("The One Ring resists all attempts to remove it!");
  4273.         }
  4274.     }
  4275.     }
  4276.     return (result);
  4277. }
  4278.  
  4279.  
  4280. /* Restores any drained experience            -RAK-     */
  4281. int 
  4282. restore_level()
  4283. {
  4284.     register int        restore;
  4285.     register struct misc *m_ptr;
  4286.  
  4287.     restore = FALSE;
  4288.     m_ptr = &py.misc;
  4289.     if (m_ptr->max_exp > m_ptr->exp) {
  4290.     restore = TRUE;
  4291.     msg_print("You feel your life energies returning.");
  4292.     /* this while loop is not redundant, ptr_exp may reduce the exp level */
  4293.     while (m_ptr->exp < m_ptr->max_exp) {
  4294.         m_ptr->exp = m_ptr->max_exp;
  4295.         prt_experience();
  4296.     }
  4297.     }
  4298.     return (restore);
  4299. }
  4300.  
  4301.  
  4302. /*
  4303.  * this fn only exists to avoid duplicating this code in the selfknowledge
  4304.  * fn. -CFT 
  4305.  */
  4306. static void 
  4307. pause_if_screen_full(i, j)
  4308.     int                *i;
  4309.     int                 j;
  4310. {
  4311.     int                 t;
  4312.  
  4313.     if (*i == 22) {           /* is screen full? */
  4314.     prt("-- more --", *i, j);
  4315.     inkey();
  4316.     for (t = 2; t < 23; t++)
  4317.         erase_line(t, j);       /* don't forget to erase extra */
  4318.     prt("Your Attributes: (continued)", 1, j + 5);
  4319.     *i = 2;
  4320.     }
  4321. }
  4322.  
  4323. /*
  4324.  * self-knowledge... idea from nethack.  Useful for determining powers and
  4325.  * resistences of items.  It saves the screen, clears it, then starts listing
  4326.  * attributes, a screenful at a time.  (There are a LOT of attributes to
  4327.  * list.  It will probably take 2 or 3 screens for a powerful character whose
  4328.  * using several artifacts...) -CFT 
  4329.  */
  4330.  
  4331. void 
  4332. self_knowledge()
  4333. {
  4334.     int                 i, j;
  4335.     int32u              f = 0L, f2 = 0L;
  4336.  
  4337.     for (i = INVEN_WIELD; i <= INVEN_LIGHT; i++) {    /* get flags from items */
  4338.     if (inventory[i].tval != TV_NOTHING) {
  4339.         if (inventory[i].p1 < 0) /* don't adjust TR_STATS if p1 is negative -CWS */
  4340.         f |= (inventory[i].flags & ~(TR_STATS | TR_SEARCH | TR_STEALTH) );
  4341.         else
  4342.         f |= inventory[i].flags;
  4343.         f2 |= inventory[i].flags2;
  4344.     }
  4345.     }
  4346.  
  4347.     save_screen();
  4348.  
  4349.     j = 15;               /* map starts at 13, but I want a couple
  4350.                     * of spaces.  This means must start by
  4351.                     * erasing map... */
  4352.     for (i = 1; i < 23; i++)
  4353.     erase_line(i, j - 2);       /* erase a couple of spaces to left */
  4354.  
  4355.     i = 1;
  4356.     prt("Your Attributes:", i++, j + 5);
  4357.  
  4358.     if (py.flags.blind > 0)
  4359.     prt("You cannot see.", i++, j);
  4360.     if (py.flags.confused > 0)
  4361.     prt("You are confused.", i++, j);
  4362.     if (py.flags.afraid > 0)
  4363.     prt("You are terrified.", i++, j);
  4364.     if (py.flags.cut > 0)
  4365.     prt("You are bleeding.", i++, j);
  4366.     if (py.flags.stun > 0)
  4367.     prt("You are stunned and reeling.", i++, j);
  4368.     if (py.flags.poisoned > 0)
  4369.     prt("You are poisoned.", i++, j);
  4370.     if (py.flags.image > 0)
  4371.     prt("You are hallucinating.", i++, j);
  4372.     if (py.flags.aggravate)
  4373.     prt("You aggravate monsters.", i++, j);
  4374.     if (py.flags.teleport)
  4375.     prt("Your position is very uncertain.", i++, j);
  4376.  
  4377.     if (py.flags.blessed > 0)
  4378.     prt("You feel rightous.", i++, j);
  4379.     if (py.flags.hero > 0)
  4380.     prt("You feel heroic.", i++, j);
  4381.     if (py.flags.shero > 0)
  4382.     prt("You are in a battle rage.", i++, j);
  4383.     if (py.flags.protevil > 0)
  4384.     prt("You are protected from evil.", i++, j);
  4385.     if (py.flags.shield > 0)
  4386.     prt("You are protected by a mystic shield.", i++, j);
  4387.     if (py.flags.invuln > 0)
  4388.     prt("You are temporarily invulnerable.", i++, j);
  4389.     if (py.flags.confuse_monster)
  4390.     prt("Your hands are glowing dull red.", i++, j);
  4391.     if (py.flags.new_spells > 0)
  4392.     prt("You can learn some more spells.", i++, j);
  4393.     if (py.flags.word_recall > 0)
  4394.     prt("You will soon be recalled.", i++, j);
  4395.  
  4396.     if (f & TR_STEALTH)
  4397.     prt("You are magically stealthy.", i++, j);
  4398.     if (f & TR_SEARCH) {
  4399.     prt("You are magically perceptive.", i++, j);
  4400.     pause_if_screen_full(&i, j);
  4401.     }
  4402.     if ((py.flags.see_infra) || (py.flags.tim_infra)) {
  4403.     prt("Your eyes are sensitive to infrared light.", i++, j);
  4404.     pause_if_screen_full(&i, j);
  4405.     }
  4406.     if ((py.flags.see_inv) || (py.flags.detect_inv)) {
  4407.     prt("You can see invisible creatures.", i++, j);
  4408.     pause_if_screen_full(&i, j);
  4409.     }
  4410.     if (py.flags.ffall) {
  4411.     prt("You land gently.", i++, j);
  4412.     pause_if_screen_full(&i, j);
  4413.     }
  4414.     if (py.flags.free_act) {
  4415.     prt("You have free action.", i++, j);
  4416.     pause_if_screen_full(&i, j);
  4417.     }
  4418.     if (py.flags.regenerate) {
  4419.     prt("You regenerate quickly.", i++, j);
  4420.     pause_if_screen_full(&i, j);
  4421.     }
  4422.     if (py.flags.slow_digest) {
  4423.     prt("Your appetite is small.", i++, j);
  4424.     pause_if_screen_full(&i, j);
  4425.     }
  4426.     if (py.flags.telepathy) {
  4427.     prt("You have ESP.", i++, j);
  4428.     pause_if_screen_full(&i, j);
  4429.     }
  4430.     if (py.flags.hold_life) {
  4431.     prt("You have a firm hold on your life force.", i++, j);
  4432.     pause_if_screen_full(&i, j);
  4433.     }
  4434.     if (py.flags.light) {
  4435.     prt("You are carrying a permanent light.", i++, j);
  4436.     pause_if_screen_full(&i, j);
  4437.     }
  4438.     if (py.flags.fear_resist) {
  4439.     prt("You are completely fearless.", i++, j);
  4440.     pause_if_screen_full(&i, j);
  4441.     }
  4442.     if (py.flags.blindness_resist) {
  4443.     prt("Your eyes are resistant to blindness.", i++, j);
  4444.     pause_if_screen_full(&i, j);
  4445.     }
  4446.     if (py.flags.fire_im) {
  4447.     prt("You are completely immune to fire.", i++, j);
  4448.     pause_if_screen_full(&i, j);
  4449.     } else if ((py.flags.fire_resist) && (py.flags.resist_heat)) {
  4450.     prt("You resist fire exceptionally well.", i++, j);
  4451.     pause_if_screen_full(&i, j);
  4452.     } else if ((py.flags.fire_resist) || (py.flags.resist_heat)) {
  4453.     prt("You are resistant to fire.", i++, j);
  4454.     pause_if_screen_full(&i, j);
  4455.     }
  4456.     if (py.flags.cold_im) {
  4457.     prt("You are completely immune to cold.", i++, j);
  4458.     pause_if_screen_full(&i, j);
  4459.     } else if ((py.flags.cold_resist) && (py.flags.resist_cold)) {
  4460.     prt("You resist cold exceptionally well.", i++, j);
  4461.     pause_if_screen_full(&i, j);
  4462.     } else if ((py.flags.cold_resist) || (py.flags.resist_cold)) {
  4463.     prt("You are resistant to cold.", i++, j);
  4464.     pause_if_screen_full(&i, j);
  4465.     }
  4466.     if (py.flags.acid_im) {
  4467.     prt("You are completely immune to acid.", i++, j);
  4468.     pause_if_screen_full(&i, j);
  4469.     } else if ((py.flags.acid_resist) && (py.flags.resist_acid)) {
  4470.     prt("You resist acid exceptionally well.", i++, j);
  4471.     pause_if_screen_full(&i, j);
  4472.     } else if ((py.flags.acid_resist) || (py.flags.resist_acid)) {
  4473.     prt("You are resistant to acid.", i++, j);
  4474.     pause_if_screen_full(&i, j);
  4475.     }
  4476.     if (py.flags.poison_im) {
  4477.     prt("You are completely immune to poison.", i++, j);
  4478.     pause_if_screen_full(&i, j);
  4479.     } else if ((py.flags.poison_resist) && (py.flags.resist_poison)) {
  4480.     prt("You resist poison exceptionally well.", i++, j);
  4481.     pause_if_screen_full(&i, j);
  4482.     } else if ((py.flags.poison_resist) || (py.flags.resist_poison)) {
  4483.     prt("You are resistant to poison.", i++, j);
  4484.     pause_if_screen_full(&i, j);
  4485.     }
  4486.     if (py.flags.light_im) {
  4487.     prt("You are completely immune to lightning.", i++, j);
  4488.     pause_if_screen_full(&i, j);
  4489.     } else if ((py.flags.lght_resist) && (py.flags.resist_light)) {
  4490.     prt("You resist lightning exceptionally well.", i++, j);
  4491.     pause_if_screen_full(&i, j);
  4492.     } else if ((py.flags.lght_resist) || (py.flags.resist_light)) {
  4493.     prt("You are resistant to lightning.", i++, j);
  4494.     pause_if_screen_full(&i, j);
  4495.     }
  4496.     if (py.flags.light_resist) {
  4497.     prt("You are resistant to bright light.", i++, j);
  4498.     pause_if_screen_full(&i, j);
  4499.     }
  4500.     if (py.flags.dark_resist) {
  4501.     prt("You are resistant to darkness.", i++, j);
  4502.     pause_if_screen_full(&i, j);
  4503.     }
  4504.     if (py.flags.confusion_resist) {
  4505.     prt("You are resistant to confusion.", i++, j);
  4506.     pause_if_screen_full(&i, j);
  4507.     }
  4508.     if (py.flags.sound_resist) {
  4509.     prt("You are resistant to sonic attacks.", i++, j);
  4510.     pause_if_screen_full(&i, j);
  4511.     }
  4512.     if (py.flags.disenchant_resist) {
  4513.     prt("You are resistant to disenchantment.", i++, j);
  4514.     pause_if_screen_full(&i, j);
  4515.     }
  4516.     if (py.flags.chaos_resist) {
  4517.     prt("You are resistant to chaos.", i++, j);
  4518.     pause_if_screen_full(&i, j);
  4519.     }
  4520.     if (py.flags.shards_resist) {
  4521.     prt("You are resistant to blasts of shards.", i++, j);
  4522.     pause_if_screen_full(&i, j);
  4523.     }
  4524.     if (py.flags.nexus_resist) {
  4525.     prt("You are resistant to nexus attacks.", i++, j);
  4526.     pause_if_screen_full(&i, j);
  4527.     }
  4528.     if (py.flags.nether_resist) {
  4529.     prt("You are resistant to nether forces.", i++, j);
  4530.     pause_if_screen_full(&i, j);
  4531.     }
  4532. /*
  4533.  * Are these needed?  The player can see this...  For now, in here for
  4534.  * completeness... -CFT 
  4535.  */
  4536.     if (f & TR_STR) {
  4537.     prt("You are magically strong.", i++, j);
  4538.     pause_if_screen_full(&i, j);
  4539.     }
  4540.     if (f & TR_INT) {
  4541.     prt("You are magically intelligent.", i++, j);
  4542.     pause_if_screen_full(&i, j);
  4543.     }
  4544.     if (f & TR_WIS) {
  4545.     prt("You are magically wise.", i++, j);
  4546.     pause_if_screen_full(&i, j);
  4547.     }
  4548.     if (f & TR_DEX) {
  4549.     prt("You are magically agile.", i++, j);
  4550.     pause_if_screen_full(&i, j);
  4551.     }
  4552.     if (f & TR_CON) {
  4553.     prt("You are magically tough.", i++, j);
  4554.     pause_if_screen_full(&i, j);
  4555.     }
  4556.     if (f & TR_CHR) {
  4557.     prt("You are magically popular.", i++, j);
  4558.     pause_if_screen_full(&i, j);
  4559.     }
  4560.     if (py.flags.sustain_str) {
  4561.     prt("You will not become weaker.", i++, j);
  4562.     pause_if_screen_full(&i, j);
  4563.     }
  4564.     if (py.flags.sustain_int) {
  4565.     prt("You will not become dumber.", i++, j);
  4566.     pause_if_screen_full(&i, j);
  4567.     }
  4568.     if (py.flags.sustain_wis) {
  4569.     prt("You will not become less wise.", i++, j);
  4570.     pause_if_screen_full(&i, j);
  4571.     }
  4572.     if (py.flags.sustain_con) {
  4573.     prt("You will not become out of shape.", i++, j);
  4574.     pause_if_screen_full(&i, j);
  4575.     }
  4576.     if (py.flags.sustain_dex) {
  4577.     prt("You will not become clumsy.", i++, j);
  4578.     pause_if_screen_full(&i, j);
  4579.     }
  4580.     if (py.flags.sustain_chr) {
  4581.     prt("You will not become less popular.", i++, j);
  4582.     pause_if_screen_full(&i, j);
  4583.     }
  4584.     if (inventory[INVEN_LEFT].flags2 & TR_ATTACK_SPD ||
  4585.     inventory[INVEN_RIGHT].flags2 & TR_ATTACK_SPD) {
  4586.     prt("You can strike at your foes with uncommon speed.", i++, j);
  4587.     pause_if_screen_full(&i, j);
  4588.     }
  4589.     if (inventory[INVEN_WIELD].tval != TV_NOTHING) {    /* this IS a bit
  4590.                              * redundant, but it
  4591.                              * prevents flags from
  4592.                              * other items from
  4593.                              * affecting the weapon
  4594.                              * stats... -CFT */
  4595.     f = inventory[INVEN_WIELD].flags;
  4596.     f2 = inventory[INVEN_WIELD].flags2;
  4597.     } else {
  4598.     f = 0L;
  4599.     f2 = 0L;
  4600.     }
  4601.     if (f & TR_CURSED) {
  4602.     if (inventory[INVEN_WIELD].name2 == SN_MORGUL)
  4603.         prt("Your weapon is truly foul.", i++, j);
  4604.     else if (inventory[INVEN_WIELD].name2 == SN_CALRIS)
  4605.         prt("Your bastard sword is wickedly accursed.", i++, j);
  4606.     else if (inventory[INVEN_WIELD].name2 == SN_MORMEGIL)
  4607.         prt("Your two-handed sword radiates an aura of unspeakable evil.", i++, j);
  4608.     else
  4609.         prt("Your weapon is accursed.", i++, j);
  4610.     pause_if_screen_full(&i, j);
  4611.     }
  4612.     if (f & TR_TUNNEL) {
  4613.     prt("Your weapon is an effective digging tool.", i++, j);
  4614.     pause_if_screen_full(&i, j);
  4615.     }
  4616.     if (f2 & TR_BLESS_BLADE) {
  4617.     prt("Your weapon has been blessed by the gods.", i++, j);
  4618.     pause_if_screen_full(&i, j);
  4619.     }
  4620.     if (f2 & TR_ATTACK_SPD) {
  4621.     prt("Your weapon strikes with uncommon speed.", i++, j);
  4622.     pause_if_screen_full(&i, j);
  4623.     }
  4624.     if (f2 & TR_SLAY_ORC) {
  4625.     prt("Your weapon is especially deadly against orcs.", i++, j);
  4626.     pause_if_screen_full(&i, j);
  4627.     }
  4628.     if (f2 & TR_SLAY_TROLL) {
  4629.     prt("Your weapon is especially deadly against trolls.", i++, j);
  4630.     pause_if_screen_full(&i, j);
  4631.     }
  4632.     if (f2 & TR_SLAY_GIANT) {
  4633.     prt("Your weapon is especially deadly against giants.", i++, j);
  4634.     pause_if_screen_full(&i, j);
  4635.     }
  4636.     if (f & TR_SLAY_ANIMAL) {
  4637.     prt("Your weapon is especially deadly against natural creatures.", i++, j);
  4638.     pause_if_screen_full(&i, j);
  4639.     }
  4640.     if (f & TR_SLAY_X_DRAGON) {
  4641.     prt("Your weapon is a great bane of dragons.", i++, j);
  4642.     pause_if_screen_full(&i, j);
  4643.     } else if (f & TR_SLAY_DRAGON) {
  4644.     prt("Your weapon is especially deadly against dragons.", i++, j);
  4645.     pause_if_screen_full(&i, j);
  4646.     }
  4647.     if (f2 & TR_SLAY_DEMON) {
  4648.     prt("Your weapon strikes at demons with holy wrath.", i++, j);
  4649.     pause_if_screen_full(&i, j);
  4650.     }
  4651.     if (f & TR_SLAY_UNDEAD) {
  4652.     prt("Your weapon strikes at undead with holy wrath.", i++, j);
  4653.     pause_if_screen_full(&i, j);
  4654.     }
  4655.     if (f & TR_SLAY_EVIL) {
  4656.     prt("Your weapon fights against evil with holy fury.", i++, j);
  4657.     pause_if_screen_full(&i, j);
  4658.     }
  4659.     if (f & TR_FROST_BRAND) {
  4660.     prt("Your frigid weapon freezes your foes.", i++, j);
  4661.     pause_if_screen_full(&i, j);
  4662.     }
  4663.     if (f & TR_FLAME_TONGUE) {
  4664.     prt("Your flaming weapon burns your foes.", i++, j);
  4665.     pause_if_screen_full(&i, j);
  4666.     }
  4667.     if (f2 & TR_LIGHTNING) {
  4668.     prt("Your weapon electrocutes your foes.", i++, j);
  4669.     pause_if_screen_full(&i, j);
  4670.     }
  4671.     if (f2 & TR_IMPACT)
  4672.     prt("The unbelievable impact of your weapon can cause earthquakes.", i++, j);
  4673.  
  4674.     pause_line(i);
  4675.     restore_screen();
  4676. }
  4677.  
  4678.  
  4679. /*
  4680.  * This function will process a bolt/ball/breath spell hitting a monster. It
  4681.  * checks for resistances, and reduces damage accordingly, and also adds in
  4682.  * what "special effects" apply to the monsters.  'rad' is used to indicate
  4683.  * the distance from "ground 0" for ball spells.  For bolts, rad should be a
  4684.  * 0.  dam is changed to reflect resistances and range. -CFT 
  4685.  */
  4686. static void 
  4687. spell_hit_monster(m_ptr, typ, dam, rad, y, x)
  4688.     monster_type       *m_ptr;
  4689.     int                 typ;
  4690.     int                *dam;
  4691.     int                 rad;
  4692.     int                *y;
  4693.     int                *x;
  4694. {
  4695.     register creature_type *r_ptr;
  4696.     int                 blind = (py.flags.status & PY_BLIND) ? 1 : 0;
  4697.     vtype               cdesc, outval;
  4698.  
  4699.     if (rad > 0)
  4700.     *dam /= rad;           /* adjust damage for range... */
  4701.  
  4702.     *y = m_ptr->fy;           /* these only change if mon gets
  4703.                     * teleported */
  4704.     *x = m_ptr->fx;
  4705.     r_ptr = &c_list[m_ptr->mptr];
  4706.     if (m_ptr->ml) {
  4707.     if (r_ptr->cdefense & UNIQUE)
  4708.         sprintf(cdesc, "%s ", r_ptr->name);
  4709.     else
  4710.         sprintf(cdesc, "The %s ", r_ptr->name);
  4711.     } else
  4712.     strcpy(cdesc, "It ");
  4713.  
  4714.     if (!blind && rad) {       /* show "hit" msg before doing effects
  4715.                     * -CFT */
  4716.     sprintf(outval, "%sis hit.", cdesc);
  4717.     msg_print(outval);
  4718.     }
  4719.     switch (typ) {           /* check for resists... */
  4720.       case GF_MAGIC_MISSILE:       /* pure damage, no resist possible */
  4721.     break;
  4722.       case GF_LIGHTNING:
  4723.     if (r_ptr->cdefense & IM_LIGHTNING) {
  4724.         if (!blind) {
  4725.         sprintf(outval, "%sresists.", cdesc);
  4726.         msg_print(outval);
  4727.         }
  4728.         *dam /= 9;
  4729.         if (m_ptr->ml)
  4730.         c_recall[m_ptr->mptr].r_cdefense |= IM_LIGHTNING;
  4731.     }
  4732.     break;
  4733.       case GF_POISON_GAS:
  4734.     if (r_ptr->cdefense & IM_POISON) {
  4735.         if (!blind) {
  4736.         sprintf(outval, "%sresists.", cdesc);
  4737.         msg_print(outval);
  4738.         }
  4739.         *dam /= 9;
  4740.         if (m_ptr->ml)
  4741.         c_recall[m_ptr->mptr].r_cdefense |= IM_POISON;
  4742.     }
  4743.     break;
  4744.       case GF_ACID:
  4745.     if (r_ptr->cdefense & IM_ACID) {
  4746.         if (!blind) {
  4747.         sprintf(outval, "%sresists.", cdesc);
  4748.         msg_print(outval);
  4749.         }
  4750.         *dam /= 9;
  4751.         if (m_ptr->ml)
  4752.         c_recall[m_ptr->mptr].r_cdefense |= IM_ACID;
  4753.     }
  4754.     break;
  4755.       case GF_FROST:
  4756.     if (r_ptr->cdefense & IM_FROST) {
  4757.         if (!blind) {
  4758.         sprintf(outval, "%sresists.", cdesc);
  4759.         msg_print(outval);
  4760.         }
  4761.         *dam /= 9;
  4762.         if (m_ptr->ml)
  4763.         c_recall[m_ptr->mptr].r_cdefense |= IM_FROST;
  4764.     }
  4765.     break;
  4766.       case GF_FIRE:
  4767.     if (r_ptr->cdefense & IM_FIRE) {
  4768.         if (!blind) {
  4769.         sprintf(outval, "%sresists.", cdesc);
  4770.         msg_print(outval);
  4771.         }
  4772.         *dam /= 9;
  4773.         if (m_ptr->ml)
  4774.         c_recall[m_ptr->mptr].r_cdefense |= IM_FIRE;
  4775.     }
  4776.     break;
  4777.       case GF_HOLY_ORB:
  4778.     if (r_ptr->cdefense & EVIL) {
  4779.         *dam *= 2;
  4780.         if (m_ptr->ml)
  4781.         c_recall[m_ptr->mptr].r_cdefense |= EVIL;
  4782.     }
  4783.     break;
  4784.       case GF_ARROW:           /* for now, no defense... maybe it should
  4785.                     * have a chance of missing? -CFT */
  4786.     break;
  4787.       case GF_PLASMA:           /* maybe IM_LIGHTNING (ball lightning is
  4788.                     * supposed to be plasma) or IM_FIRE
  4789.                     * (since it's hot)? -CFT */
  4790.     if (!strncmp("Plasma", r_ptr->name, 6) ||
  4791.         (r_ptr->spells3 & BREATH_PL)) {    /* if is a "plasma" monster,
  4792.                          * or can breathe plasma,
  4793.                          * then we assume it should
  4794.                          * be immune. plasma bolts
  4795.                          * don't count, since
  4796.                          * mage-types could have
  4797.                          * them, and not deserve
  4798.                          * plasma-resist -CFT */
  4799.         if (!blind) {
  4800.         sprintf(outval, "%sresists.", cdesc);
  4801.         msg_print(outval);
  4802.         }
  4803.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  4804.                     * ranging */
  4805.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  4806.     }
  4807.     break;
  4808.       case GF_NETHER:           /* I assume nether is an evil, necromantic
  4809.                     * force, so it doesn't hurt undead, and
  4810.                     * hurts evil less -CFT */
  4811.     if (r_ptr->cdefense & UNDEAD) {
  4812.         if (!blind) {
  4813.         sprintf(outval, "%sseems immune.", cdesc);
  4814.         msg_print(outval);
  4815.         }
  4816.         *dam = 0;
  4817.         if (m_ptr->ml)
  4818.         c_recall[m_ptr->mptr].r_cdefense |= UNDEAD;
  4819.     } else if (r_ptr->spells2 & BREATH_LD) {    /* if can breath nether,
  4820.                              * should get good
  4821.                              * resist to damage -CFT */
  4822.         if (!blind) {
  4823.         sprintf(outval, "%sresists.", cdesc);
  4824.         msg_print(outval);
  4825.         }
  4826.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  4827.                     * ranging */
  4828.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  4829.     } else if (r_ptr->cdefense & EVIL) {
  4830.         *dam /= 2;           /* evil takes *2 for holy, so /2 for
  4831.                     * this... -CFT */
  4832.         if (!blind) {
  4833.         sprintf(outval, "%sresists somewhat.", cdesc);
  4834.         msg_print(outval);
  4835.         }
  4836.         if (m_ptr->ml)
  4837.         c_recall[m_ptr->mptr].r_cdefense |= EVIL;
  4838.     }
  4839.     break;
  4840.       case GF_WATER:           /* water elementals should resist.  anyone
  4841.                     * else? -CFT */
  4842.     if ((r_ptr->cchar == 'E') && (r_ptr->name[0] == 'W')) {
  4843.         if (!blind) {
  4844.         sprintf(outval, "%sseems immune.", cdesc);
  4845.         msg_print(outval);
  4846.         }
  4847.         *dam = 0;           /* water spirit, water ele, and Waldern
  4848.                     * -CFT */
  4849.     }
  4850.     break;
  4851.       case GF_CHAOS:
  4852.     if (r_ptr->spells2 & BREATH_CH) {    /* assume anything that
  4853.                          * breathes chaos is chaotic
  4854.                          * enough to deserve
  4855.                          * resistance... -CFT */
  4856.         if (!blind) {
  4857.         sprintf(outval, "%sresists.", cdesc);
  4858.         msg_print(outval);
  4859.         }
  4860.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  4861.                     * ranging */
  4862.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  4863.     }
  4864.     if (*dam > m_ptr->hp)
  4865.         break;           /* don't bother with special effects...
  4866.                     * it's dead! -CFT */
  4867.     if (!(r_ptr->spells2 & BREATH_CH) &&
  4868.         !(r_ptr->cdefense & UNIQUE) &&
  4869.         (randint(100) > r_ptr->level)) {    /* then we'll polymorph it
  4870.                          * -CFT */
  4871.         int                 i, j, k;
  4872.  
  4873.         if (!blind) {
  4874.         sprintf(outval, "%schanges.", cdesc);
  4875.         msg_print(outval);
  4876.         }
  4877.         i = (randint(20) / randint(9)) + 1;
  4878.         j = r_ptr->level - i;  /* get range of levels... */
  4879.         k = r_ptr->level + i;
  4880.         if (j < 0)
  4881.         j = 0;
  4882.         if (k > MAX_MONS_LEVEL)
  4883.         k = MAX_MONS_LEVEL;
  4884.         delete_monster(cave[*y][*x].cptr);
  4885.         do {
  4886.         i = randint(m_level[k] - m_level[j]) - 1 + m_level[j];    /* monster index */
  4887.         if ((c_list[i].cdefense & UNIQUE) == 0)
  4888.             place_monster(*y, *x, i, FALSE);
  4889.         } while (cave[*y][*x].cptr < MIN_MONIX);    /* until we get
  4890.                              * something-CFT */
  4891.     }
  4892.     /*
  4893.      * end of chaos-poly.  If was poly-ed don't bother confuse... it's too
  4894.      * hectic to keep track of... -CFT 
  4895.      */ 
  4896.     else if (!(r_ptr->cdefense & CHARM_SLEEP) &&
  4897.          !(r_ptr->spells2 & BREATH_CH) &&    /* choatics hard to
  4898.                              * confuse */
  4899.          !(r_ptr->spells2 & BREATH_CO))    /* so are bronze dragons */
  4900.         if (m_ptr->confused > 0) {
  4901.         if (m_ptr->confused < 240) {    /* make sure not to overflow
  4902.                          * -CFT */
  4903.             if (!blind) {
  4904.             sprintf(outval, "%sis more confused.", cdesc);
  4905.             msg_print(outval);
  4906.             }
  4907.             m_ptr->confused += 7 / (rad > 0 ? rad : 1);
  4908.         }
  4909.         } else {
  4910.         if (!blind) {
  4911.             sprintf(outval, "%sis confused.", cdesc);
  4912.             msg_print(outval);
  4913.         }
  4914.         m_ptr->confused = (randint(11) + 5) / (rad > 0 ? rad : 1);
  4915.         }
  4916.     break;
  4917.       case GF_SHARDS:
  4918.     if (r_ptr->spells2 & BREATH_SH) {    /* shard breathers resist
  4919.                          * -CFT */
  4920.         if (!blind) {
  4921.         sprintf(outval, "%sresists.", cdesc);
  4922.         msg_print(outval);
  4923.         }
  4924.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  4925.                     * ranging */
  4926.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  4927.     }
  4928.     break;
  4929.       case GF_SOUND:
  4930.     if (r_ptr->spells2 & BREATH_SD) {    /* ditto for sound -CFT */
  4931.         if (!blind) {
  4932.         sprintf(outval, "%sresists.", cdesc);
  4933.         msg_print(outval);
  4934.         }
  4935.         *dam *= 2;
  4936.         *dam /= (randint(6) + 6);
  4937.     }
  4938.     if (*dam > m_ptr->hp)
  4939.         break;           /* don't bother with special effects...
  4940.                     * it's dead! -CFT */
  4941.     if (!(r_ptr->spells2 & BREATH_SD) &&
  4942.         !(r_ptr->spells3 & BREATH_WA))    /* sound and impact breathers
  4943.                          * should not stun -CFT */
  4944.         if (m_ptr->confused > 0) {
  4945.         if (m_ptr->confused < 220) {    /* make sure not to overflow
  4946.                          * -CFT */
  4947.             if (!blind) {
  4948.             sprintf(outval, "%sis more dazed.", cdesc);
  4949.             msg_print(outval);
  4950.             }
  4951.             m_ptr->confused += (randint(5) * 2) / (rad > 0 ? rad : 1);
  4952.         }
  4953.         } else {
  4954.         if (!blind) {
  4955.             sprintf(outval, "%sis dazed.", cdesc);
  4956.             msg_print(outval);
  4957.         }
  4958.         m_ptr->confused = (randint(15) + 10) / (rad > 0 ? rad : 1);
  4959.         }
  4960.     break;
  4961.       case GF_CONFUSION:
  4962.     if (r_ptr->spells2 & BREATH_CO) {
  4963.         if (!blind) {
  4964.         sprintf(outval, "%sresists.", cdesc);
  4965.         msg_print(outval);
  4966.         }
  4967.         *dam *= 2;
  4968.         *dam /= (randint(6) + 6);
  4969.     } else if (r_ptr->cdefense & CHARM_SLEEP) {
  4970.         if (!blind) {
  4971.         sprintf(outval, "%sresists somewhat.", cdesc);
  4972.         msg_print(outval);
  4973.         }
  4974.         *dam /= 2;           /* only some resist, but they also avoid
  4975.                     * confuse -CFT */
  4976.     }
  4977.     if (*dam > m_ptr->hp)
  4978.         break;           /* don't bother with special effects...
  4979.                     * it's dead! -CFT */
  4980.     if (!(r_ptr->cdefense & CHARM_SLEEP) &&
  4981.         !(r_ptr->spells2 & BREATH_CH) &&    /* chaotics hard to confuse */
  4982.         !(r_ptr->spells2 & BREATH_CO))    /* so are bronze dragons */
  4983.         if (m_ptr->confused > 0) {
  4984.         if (m_ptr->confused < 240) {    /* make sure not to overflow
  4985.                          * -CFT */
  4986.             if (!blind) {
  4987.             sprintf(outval, "%sis more confused.", cdesc);
  4988.             msg_print(outval);
  4989.             }
  4990.             m_ptr->confused += 7 / (rad > 0 ? rad : 1);
  4991.         }
  4992.         } else {
  4993.         if (!blind) {
  4994.             sprintf(outval, "%sis confused.", cdesc);
  4995.             msg_print(outval);
  4996.         }
  4997.         m_ptr->confused = (randint(11) + 5) / (rad > 0 ? rad : 1);
  4998.         }
  4999.     break;
  5000.       case GF_DISENCHANT:
  5001.     if ((r_ptr->spells2 & BREATH_DI) ||
  5002.         !strncmp("Disen", r_ptr->name, 5)) {
  5003.         if (!blind) {
  5004.         sprintf(outval, "%sresists.", cdesc);
  5005.         msg_print(outval);
  5006.         }
  5007.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5008.                     * ranging */
  5009.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5010.     }
  5011.     break;
  5012.       case GF_NEXUS:
  5013.     if ((r_ptr->spells2 & BREATH_NE) ||
  5014.         !strncmp("Nexus", r_ptr->name, 5)) {
  5015.         if (!blind) {
  5016.         sprintf(outval, "%sresists.", cdesc);
  5017.         msg_print(outval);
  5018.         }
  5019.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5020.                     * ranging */
  5021.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5022.     }
  5023.     break;
  5024.       case GF_FORCE:
  5025.     if (r_ptr->spells3 & BREATH_WA) {    /* breath ele force resists
  5026.                          * ele force -CFT */
  5027.         if (!blind) {
  5028.         sprintf(outval, "%sresists.", cdesc);
  5029.         msg_print(outval);
  5030.         }
  5031.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5032.                     * ranging */
  5033.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5034.     }
  5035.     if (*dam > m_ptr->hp)
  5036.         break;           /* don't bother with special effects...
  5037.                     * it's dead! -CFT */
  5038.     if (!(r_ptr->spells2 & BREATH_SD) &&
  5039.         !(r_ptr->spells3 & BREATH_WA) &&
  5040.         !(r_ptr->cdefense & CHARM_SLEEP) &&
  5041.         !(r_ptr->cdefense & UNIQUE))    /* sound and impact breathers
  5042.                          * should not stun -CFT */
  5043.     /* Nor should uniques -DGK */
  5044.         if (m_ptr->confused > 0) {
  5045.         if (m_ptr->confused < 220) {    /* make sure not to overflow
  5046.                          * -CFT */
  5047.             if (!blind) {
  5048.             sprintf(outval, "%sis more dazed.", cdesc);
  5049.             msg_print(outval);
  5050.             }
  5051.             m_ptr->confused += ((m_ptr->confused <= 0) ?
  5052.                   ((randint(5) + 1) / (rad > 0 ? rad : 1)) :
  5053.                     (randint(2) / (rad > 0 ? rad : 1)));
  5054.         /*
  5055.          * Confuse addition reworked because of Spirit.Hammer prayer
  5056.          * -DGK 
  5057.          */
  5058.         }
  5059.         } else {
  5060.         if (!blind) {
  5061.             sprintf(outval, "%sis dazed.", cdesc);
  5062.             msg_print(outval);
  5063.         }
  5064.         m_ptr->confused = randint(15) / (rad > 0 ? rad : 1);
  5065.         }
  5066.     break;
  5067.       case GF_INERTIA:
  5068.     if (r_ptr->spells3 & BREATH_SL) {    /* if can breath inertia,
  5069.                          * then resist it. */
  5070.         if (!blind) {
  5071.         sprintf(outval, "%sresists.", cdesc);
  5072.         msg_print(outval);
  5073.         }
  5074.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5075.                     * ranging */
  5076.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5077.     }
  5078.     break;
  5079.       case GF_LIGHT:
  5080.     if (r_ptr->spells3 & BREATH_LT) {    /* breathe light to res light */
  5081.         if (!blind) {
  5082.         sprintf(outval, "%sresists.", cdesc);
  5083.         msg_print(outval);
  5084.         }
  5085.         *dam *= 2;
  5086.         *dam /= (randint(6) + 6);
  5087.     } else if (r_ptr->cdefense & HURT_LIGHT) {
  5088.         *dam *= 2;           /* hurt bad by light */
  5089.     } else if (r_ptr->spells3 & BREATH_DA) {    /* breathe dark gets
  5090.                              * hurt */
  5091.         *dam = (*dam * 3) / 2;
  5092.     }
  5093.     break;
  5094.       case GF_DARK:
  5095.     if (r_ptr->spells2 & BREATH_DA) {    /* dark breathers resist -CFT */
  5096.         if (!blind) {
  5097.         sprintf(outval, "%sresists.", cdesc);
  5098.         msg_print(outval);
  5099.         }
  5100.         *dam *= 2;
  5101.         *dam /= (randint(6) + 6);
  5102.     } else if (r_ptr->cdefense & HURT_LIGHT) {
  5103.         *dam /= 2;           /* hurt bad by light, so not hurt bad by
  5104.                     * dark */
  5105.     } else if (r_ptr->spells3 & BREATH_LT) {    /* breathe light gets
  5106.                              * hurt */
  5107.         *dam = (*dam * 3) / 2;
  5108.     }
  5109.     break;
  5110.       case GF_TIME:
  5111.     if (r_ptr->spells3 & BREATH_TI) {    /* time breathers resist -CFT */
  5112.         if (!blind) {
  5113.         sprintf(outval, "%sresists.", cdesc);
  5114.         msg_print(outval);
  5115.         }
  5116.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5117.                     * ranging */
  5118.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5119.     }
  5120.     break;
  5121.       case GF_GRAVITY:
  5122.     if (r_ptr->spells3 & BREATH_GR) {    /* breathers resist -CFT */
  5123.         if (!blind) {
  5124.         sprintf(outval, "%sresists.", cdesc);
  5125.         msg_print(outval);
  5126.         }
  5127.         *dam *= 3;           /* these 2 lines give avg dam of .33,
  5128.                     * ranging */
  5129.         *dam /= (randint(6) + 6);    /* from .427 to .25 -CFT */
  5130.     } else {
  5131.         if (*dam > m_ptr->hp)
  5132.         break;           /* don't bother with special effects...
  5133.                     * it's dead! -CFT */
  5134.         teleport_away(cave[m_ptr->fy][m_ptr->fx].cptr, 5);
  5135.         *y = m_ptr->fy;       /* teleported, so let outside world know
  5136.                     * monster moved! */
  5137.         *x = m_ptr->fx;
  5138.     }
  5139.     break;
  5140.       case GF_MANA:           /* raw blast of power. no way to resist,
  5141.                     * is there? */
  5142.     break;
  5143.       case GF_METEOR:           /* GF_METEOR is basically a powerful
  5144.                     * magic-missile ball spell.  I only made
  5145.                     * it a different type so I could make it
  5146.                     * a different color -CFT */
  5147.     break;
  5148.       case GF_ICE:           /* ice is basically frost + cuts + stun
  5149.                     * -CFT */
  5150.     if (r_ptr->cdefense & IM_FROST) {
  5151.         if (!blind) {
  5152.         sprintf(outval, "%sresists.", cdesc);
  5153.         msg_print(outval);
  5154.         }
  5155.         *dam /= 9;
  5156.         if (m_ptr->ml)
  5157.         c_recall[m_ptr->mptr].r_cdefense |= IM_FROST;
  5158.     }
  5159.     if (*dam > m_ptr->hp)
  5160.         break;           /* don't bother with special effects...
  5161.                     * it's dead! -CFT */
  5162.     if (!(r_ptr->spells2 & BREATH_SD) &&
  5163.         !(r_ptr->spells3 & BREATH_WA))    /* sound and impact breathers
  5164.                          * should not stun -CFT */
  5165.         if (m_ptr->confused > 0) {
  5166.         if (m_ptr->confused < 220) {    /* make sure not to overflow
  5167.                          * -CFT */
  5168.             if (!blind) {
  5169.             sprintf(outval, "%sis more dazed.", cdesc);
  5170.             msg_print(outval);
  5171.             }
  5172.             m_ptr->confused += (randint(5) + 1) / (rad > 0 ? rad : 1);
  5173.         }
  5174.         } else {
  5175.         if (!blind) {
  5176.             sprintf(outval, "%sis dazed.", cdesc);
  5177.             msg_print(outval);
  5178.         }
  5179.         m_ptr->confused = randint(15) / (rad > 0 ? rad : 1);
  5180.         }
  5181.     break;
  5182.       default:
  5183.     msg_print("Unknown typ in spell_hit_monster.  This may mean trouble.");
  5184.     } /* end switch for saving throws and extra effects */
  5185. }
  5186.